/** * @brief Check out a hash table for insertion. * * @note This method is relevant for specialized (for aggregation) * hash table implementation. * * @return A hash table pointer. **/ AggregationStateHashTableBase* getHashTable() { { SpinMutexLock lock(mutex_); if (!hash_tables_.empty()) { std::unique_ptr<AggregationStateHashTableBase> ret_hash_table( std::move(hash_tables_.back())); hash_tables_.pop_back(); DCHECK(ret_hash_table != nullptr); return ret_hash_table.release(); } } return createNewHashTable(); }
int main(int argc, char **argv) { HashObjectPtr p; char * line = (char *)malloc(sizeof(char)*MAX_INPUT_LENGTH); printOptions(); while (fgets(line, MAX_INPUT_LENGTH, stdin)!=NULL) { switch (line[0]) { case 'c': if (table == NULL) { if ((table = createNewHashTable()) == NULL) { printOptions(); break; } else { printf("\n\nSuccess. What would you like to do now?\n\n"); printOptions(); } } else { FreeHashTable(table); if ((table = createNewHashTable()) == NULL) { printOptions(); break; } else { printf("\n\nSuccess. What would you like to do now?\n\n"); printOptions(); } } break; case 'l': if (table == NULL) { printf("You need to first instantiate a hashtable, use the 'c' option\n\n"); break; } else { if ((p = wordSearch(table)) != NULL) { printf("\n\nSuccess. What would you like to do now?\n\n"); printOptions(); } else { printOptions(); } } break; case 'f': if (table == NULL) { printf("You need to first instantiate a hashtable, use the 'c' option\n\n"); break; } if (uploadAndRunFile(table) != NULL) { printf("\n\nSuccess. What would you like to do now?\n\n"); printOptions(); } break; case 'p': if (table == NULL) { printf("You need to first instantiate a hashtable, use the 'c' option\n\n"); break; } printf("\n\nPrinting Hash Table\n\n"); PrintHash(table); printf("\n\nSuccess. What would you like to do now?\n\n"); printOptions(); break; case 'r': if (table == NULL) { printf("You need to first instantiate a hashtable, use the 'c' option\n\n"); break; } removeThings(); break; case 'q': FreeHashTable(table); free(line); printf("\n\nGoodbye\n\n"); return 0; case 's': if (table == NULL) { printf("You need to first instantiate a hashtable, use the 'c' option\n\n"); break; } break; default: printf("%s\n", "That is an unrecognized entry, please try again\n\n"); printOptions(); break; } } free(line); return 0; }