int findinHashtable(Hashtable H, Lexeme L, int hashtablesize) { int index; int j = 0; index = stringHashFunction(L.lexName, hashtablesize); if(strcmp(H[index].lexemeName, L.lexName) == 0) { return index; } else { do { index = getNextAddress(index, j, hashtablesize); j++; }while(strcmp(H[index].lexemeName, L.lexName) != 0 && j<hashtablesize); } if(j>=hashtablesize) { //printf("NOT FOUND IN HASHTABLE: ERROR!!"); return -1; } else return index; }
void TableManager::insert(Token &tkIdentifier, TableEntry* tabEntry) { if(tabEntry->getEntryType() == TableEntry::FUNCTION) { currentAddress = FUNCTION_BASE_ADDRESS; currentFunction = (FunctionEntry*)tabEntry; } else { currentAddress = tabEntry->setAddress( getNextAddress() ); } currentTable->insert( tkIdentifier, tabEntry ); }
/** * Physically write to EEPROM */ void EEPROMUtil::write(const String& key, const String& value) { String str = key + splitChar + value + newLineChar; int address = getNextAddress(); for (int j = 0; j < str.length(); ++j) { EEPROM.write(address, str[j]); address++; } delay(10); EEPROM.commit(); Log.info("stored in the eeprom"); }
void Service::run() { _runFlag = true; _serviceSocket = new net::ServerSocket(_port); _serviceSocket->listen(); while(_runFlag) { net::Socket& socket = _serviceSocket->accept(); iostream::XdrInputStream& istream = socket.getXdrInputStream(); iostream::XdrOutputStream& ostream = socket.getXdrOutputStream(); int requestType = 0; ostream.flush(); ostream.write(net::MessageProtocol::REPLY); ostream.flush(); istream.read(requestType); // istream.flush(); if (requestType == net::MessageProtocol::ADDADDRESS) { addAddress(istream, ostream); } else if (requestType == net::MessageProtocol::REMOVEADDRESS) { removeAddress(istream, ostream); } else if (requestType == net::MessageProtocol::GETAVAILABLEADDRESS) { getNextAddress(istream, ostream); } else { handleError(istream, ostream); } socket.close(); } delete _serviceSocket; }
Hashtable addLexemetoTable(Hashtable H, Lexeme L, Lexeme* RHShead, int Hashtablesize) { int index; int j; int k=0; index = stringHashFunction(L.lexName, HASHTABLE_SIZE); if (strcmp(L.lexName, "logicalOp") == 0) { //printf("HERE %s - %s \n", L.lexName, H[index].lexemeName); } if(strcmp(H[index].lexemeName, "") == 0) { strcpy(H[index].lexemeName, L.lexName); j=0; while(H[index].nextLexeme[j] != 0 && j<HPR) //if index found is empty directly { j++; } if(j>=HPR) { printf("Terminal at hashindex %d needs more than HPR pointers! Error", index); return H; } H[index].nextLexeme[j] = RHShead; return H; } else if(strcmp(H[index].lexemeName, L.lexName) == 0) // if both have same name(means production is of form A --> XYZ | PQR) find next free pointer and add the RHS there { for(j=0;j<HPR; j++) { if(H[index].nextLexeme[j] == NULL) { H[index].nextLexeme[j] = RHShead; return H; } } if(j>=HPR) { printf("Terminal at hashindex %d needs more than HPR pointers! Error", index); return H; } } else //need to probe { do { index = getNextAddress(index, k, HASHTABLE_SIZE); k++; if(k==Hashtablesize) { printf("Hashtable full!!\n"); return NULL; } if(strcmp(H[index].lexemeName, L.lexName) == 0) { for(j=0;j<HPR; j++) { if(H[index].nextLexeme[j] == NULL) { H[index].nextLexeme[j] = RHShead; return H; } } if(j>=HPR) { printf("Terminal at hashindex %d needs more than HPR pointers! Error", index); return H; } } }while(strcmp(H[index].lexemeName, "") != 0 && k<Hashtablesize); strcpy(H[index].lexemeName, L.lexName); j=0; while(H[index].nextLexeme[j] != 0 && j<HPR) { j++; } if(j>=HPR) { printf("Terminal at hashindex %d needs more than HPR pointers! Error", index); return H; } H[index].nextLexeme[j] = RHShead; return H; } return H; }