Exemple #1
0
void interactive()
{
	HashTable* ht = makeTable(22);
	for (unsigned i = 0; i < 27; ++i) {
		ht = insertTable(ht, namen[i], rand() % 100);
	}
	printHashTable(ht);
	while (1) {
		unsigned i;
		printf( "Insert (2) or search (1) or delete (0)? " );
		scanf(  "%u", &i );
		if (i == 2) {
			printf( "Name: " );
			char* name = getline();
			unsigned telNr;
			printf( "Telephone-Nr.: " );
			scanf("%u", &telNr);
			ht = insertTable(ht, name, telNr);
			printHashTable(ht);
		} else if (i == 1) {
			printf( "Name: " );
			char* name = getline();
			unsigned* telNr = searchTable(ht, name);
			printf( "Telephone-Nr.: %u\n", *telNr );
		} else {
			printf( "Name: " );
			char* name = getline();
			deleteTable(ht, name);
			printHashTable(ht);
		}
	}
}
Exemple #2
0
int database::createTable(char * tableName)
{
    if (usedTables < numberOfTables && searchTable(tableName) == notFound)
    {
        tableArray[usedTables] = new table(tableName);
        usedTables++;
        return (usedTables-1);
    }
    return -1;
}
// Expunge deleted tags from the local database
void SyncRunner::syncRemoteExpungedSavedSearches(QList<Guid> guids) {
    QLOG_TRACE() << "Entering SyncRunner::syncRemoteExpungedSavedSearches";
    SearchTable searchTable(db);
    for (int i=0; i<guids.size(); i++) {
        int lid = searchTable.getLid(guids[i]);
        searchTable.expunge(guids[i]);
        if (!finalSync)
            emit searchExpunged(lid);
    }
    QLOG_TRACE() << "Leaving SyncRunner::syncRemoteExpungedSavedSearches";
}
Exemple #4
0
void CountWord(HashTablePtr table, char * checkword) {
	NodePtr tempNode;
	WordObjPtr word = (WordObjPtr) malloc(sizeof(WordObjPtr));
	word = createWordObj(checkword, 0);

	printf("created temp node and word object from word\n");
	tempNode = searchTable(table, (void *) word);
	printf("ran searchTable\n");
	if (tempNode != NULL) {
		printf("found word\n");
		WordObjPtr tempWord;
		tempWord = tempNode->obj;
		tempWord->frequency++;
		return;
	}
	word->frequency++;
	printf("did not find word adding\n");
	insert(table, (void *) word);

	return;
}
//***********************************************************
//* Process a <savedsearch> node.
//***********************************************************
void ImportData::processSavedSearchNode() {
    QLOG_DEBUG() << "Processing Saved Search Node";

    SavedSearch search;
    bool searchIsDirty = false;
    SearchTable searchTable(global.db);

    bool atEnd = false;

    // Keep going until we hit </savedsearch>
    while(!atEnd) {
        if (reader->isStartElement()) {
            QString name = reader->name().toString().toLower();
            if (name == "guid")  {
                search.guid = textValue();
            }
            if (name == "name") {
                search.name = textValue();
            }
            if (name == "updatesequencenumber") {
                search.updateSequenceNum = intValue();
            }
            if (name == "query") {
                search.query = textValue();
            }
            if (name == "dirty") {
                if (booleanValue())
                    searchIsDirty = true;
            }
        }
        reader->readNext();
        QString endName = reader->name().toString().toLower();
        if (endName == "savedsearch" && reader->isEndElement())
            atEnd = true;
    }

    // Add this search to the table
    searchTable.add(0,search, searchIsDirty);
    return;
}
// Synchronize remote searches with the current database
// If there is a conflict, the remote wins
void SyncRunner::syncRemoteSearches(QList<SavedSearch> searches) {
    QLOG_TRACE() << "Entering SyncRunner::syncRemoteSearches";
    SearchTable searchTable(db);

    for (int i=0; i<searches.size() && keepRunning; i++) {
        SavedSearch t = searches.at(i);
        qint32 lid = searchTable.getLid(t.guid);
        if (lid > 0) {
            searchTable.sync(lid, t);
        } else {
            searchTable.sync(t);
            lid = searchTable.getLid(t.guid);
        }
        if (!finalSync) {
            if (t.name.isSet())
                emit searchUpdated(lid, t.name);
            else
                emit searchUpdated(lid, "");
        }
    }

    QLOG_TRACE() << "Leaving SyncRunner::syncRemoteSearches";
}
Exemple #7
0
//**************************************************************************
bool fatpredict_t::inTable( la_t vpc )
{
  return (searchTable(vpc) >= 0);
}
int main() {
    
    char filename[MAX_SIZE+1], temp[MAX_SIZE+1];
    FILE *ifp;
    int numwords, i;
    struct htable mytable;
    int ans;
    
    // Get the file name.
    printf("What is the name of the dictionary file?\n");
    scanf("%s", &filename);
    ifp = fopen(filename, "r");
    
    fscanf(ifp, "%d", &numwords);
    
    // Read in all of the words from a file into the table.
    // This is only done once.
    printf("get here\n");
    initTable(&mytable);
    printf("iniit table\n");
    
    for (i=0; i<numwords; i++) {
        fscanf(ifp, "%s", temp);
        insertTable(&mytable, temp);
    }
    
    
    // Allow the user to make changes to the hash table and search for words.
    do {
       
        printf("Do you want to 1)search word, 2) add word, 3) delete a word?\n");
        scanf("%d", &ans);
       
        // Search for a word.
        if (ans == 1) {
                   
            printf("What word are you looking for?\n");
            scanf("%s", temp);
            if (searchTable(&mytable, temp))
                printf("%s was found.\n", temp);
            else
                printf("%s was NOT found.\n", temp);     
        }    
        
        // Add a word.
        else if (ans == 2) {
            
            printf("What word do you want to add?\n");
            scanf("%s", temp);
            if (searchTable(&mytable, temp))
                printf("%s was ALREADY in the table\n", temp);
            else 
                insertTable(&mytable, temp);     
        }
        
        // Delete a word.
        else if (ans == 3) {
        
            printf("What word do you want to delete?\n");
            scanf("%s", temp);
            deleteTable(&mytable, temp);
                 
        }
        
    } while (ans < 4); // Not very user friendly, just quits for any number > 3.
    
    system("PAUSE");
    return 0;
}