static DXLError InitializeObjectHandler(DXLConnection *conn) { conn->objectHandlerDict = NewDictionary(); if (!conn->objectHandlerDict) return ERROR; if (!_dxl_SetSystemHandlerString(conn, PACK_INFO, link_object_token, SystemObjectHandler, NULL) || !_dxl_SetSystemHandlerString(conn, PACK_LINK, object_token, SystemObjectHandler, NULL)) return ERROR; return OK; }
int main () { DictHndl testHash; ListHndl testLookUp; testHash = NewDictionary (10); InsertKey (testHash, "cat", 123); InsertKey (testHash, "dog", 234); InsertKey (testHash, "fog", 2345); InsertKey (testHash, "fog", 245); testLookUp = LookUp (testHash, "fog"); MoveFirst (testLookUp); while (!OffEnd (testLookUp)) { int temp = *(int*) GetCurrent (testLookUp); printf ("%d ", temp); MoveNext (testLookUp); } printf ("\n"); if (IsIn (testHash, "dog")) { printf ("dog is in the table\n"); } DeleteKey (testHash, "cat"); DeleteKey (testHash, "dog"); if (IsIn (testHash, "dog")) { printf ("dog is still in the table\n"); } testLookUp = LookUp (testHash, "dog"); FreeDictionary (testHash); return (0); }
int main () { DictHndl testDict; ListHndl testLookUp; testDict = NewDictionary (10); InsertKey (testDict, "cat", 123); InsertKey (testDict, "dog", 234); InsertKey (testDict, "fog", 2345); InsertKey (testDict, "fog", 245); testLookUp = LookUp (testDict, "cat"); printf ("%d\n" , *(int*) GetFirst (testLookUp)); PrintKeyLocations (testDict, "fog"); if (IsIn (testDict, "dog")) { printf ("dog is in the table\n"); } DeleteKey (testDict, "cat"); DeleteKey (testDict, "dog"); if (IsIn (testDict, "dog")) { printf ("dog is still in the table\n"); } FreeDictionary (testDict); return (0); }
int main ( int argc, char* argv []) { int i, j; DictHndl library; int numBooks; int dictSize; int parser; int parseSave; int numSearches; FILE *libraryBooks; FILE *searchBooks; char buffer[1000]; if (argc != 3) { fprintf (stderr, "usage: %s filename filename\n", argv[0]); return 1; } libraryBooks = fopen( argv[1], "r"); searchBooks = fopen ( argv[2], "r"); if (libraryBooks == 0 || searchBooks == 0) { fprintf (stderr, "File does not exist\n"); return 1; } fgets (buffer, 1000, libraryBooks); parser = 0; while (buffer[parser] >= '0' && buffer[parser] <= '9') { parser++; } parseSave = parser; parser--; numBooks = 0; for (j = 1; parser >= 0; j = j * 10) { numBooks += (buffer[parser] - '0') * j; parser--; } parser = parseSave + 1; while (buffer[parser] >= '0' && buffer[parser] <= '9') { parser++; } dictSize = 0; for (j = 1; parser > parseSave; j = j * 10) { dictSize += (buffer[parser] - '0') * j; parser--; } library = NewDictionary (dictSize); for (i = 0; i < numBooks; i++) { int reparser = 0; int tempLocation = 0; parser = 0; fgets (buffer, 1000, libraryBooks); while (buffer[parser] != ',') { if (parser == 999) { fprintf (stderr, "Improper Library Data File\n"); return 1; } parser++; } parseSave = parser; parser--; for (j = 1; parser >= 0; j = j * 10) { tempLocation += (buffer[parser] - '0') * j; parser--; } parser = parseSave; parser += 2; while (buffer[parser] != '\n' && buffer[parser] != EOF && buffer[parser] != '\0') { buffer[reparser] = buffer[parser]; parser++; reparser++; } buffer[reparser] = '\0'; InsertKey (library, buffer, tempLocation); } fgets (buffer, 1000, searchBooks); parser = 0; while (buffer[parser] >= '0' && buffer[parser] <= '9') { parser++; } parser--; numSearches = 0; for (j = 1; parser >= 0; j = j * 10) { numSearches += (buffer[parser] - '0') * j; parser--; } for (i = 0; i < numSearches; i++) { fgets (buffer, 1000, searchBooks); j = 0; while (buffer[j] != '\n' && buffer[j] != '\0' && buffer[j] != EOF) { j++; } buffer[j] = '\0'; PrintKeyLocations (library, buffer); } FreeDictionary (library); fclose (libraryBooks); fclose (searchBooks); return 0; }