/* main */ int main(int argc, char* argv[]) { LINKEDLIST *self; PERSONALINFO *personInfo; CreateLinkedList(&self); AddPersonalInfo(&personInfo, "kim", "111", "seoul", FALSE); AppendLinkedList(&self, &personInfo); AddPersonalInfo(&personInfo, "lee", "222", "busan", FALSE); AppendLinkedList(&self, &personInfo); AddPersonalInfo(&personInfo, "park", "333", "inchon", FALSE); InsertLinkedList(&self, 2, &personInfo); DeleteLinkedList(&self, 3); //DeleteLinkedList(&self, 1); //DeleteLinkedList(&self, 1); personInfo = ViewAtLinkedList(&self, 2); printf("name : %s\nphone : %s\naddress : %s\nflag : %d\n", personInfo->name, personInfo->phone, personInfo->address, personInfo->flagOfDelete); DestroyLinkedList(&self); return 0; }
static void AddToHashtable(HashTable tab, char *word, DocPositionOffset_t pos) { HTKey_t hashKey; int retval; HTKeyValue kv; // Hash the string. hashKey = FNVHash64((unsigned char *) word, strlen(word)); // Have we already encountered this word within this file? // If so, it's already in the hashtable. retval = LookupHashTable(tab, hashKey, &kv); if (retval == 1) { // Yes; we just need to add a position in using AppendLinkedList(). Note // how we're casting the DocPositionOffset_t position // variable to an LLPayload_t to store // it in the linked list payload without needing to malloc space for it. // Ugly, but it works! WordPositions *wp = (WordPositions *) kv.value; retval = AppendLinkedList(wp->positions, (LLPayload_t) ((intptr_t) pos)); Verify333(retval != 0); } else { // STEP 8. // No; this is the first time we've seen this word. Allocate and prepare // a new WordPositions structure, and append the new position to its list // using a similar ugly hack as right above. WordPositions *wp; char *newstr; HTKeyValue oldkv; bool retbool; // Allocate space for a new WordPositions structure. wp = (WordPositions *)malloc(sizeof(WordPositions)); Verify333(wp != NULL); // Allocate space for the word and copy the word content. newstr = (char *)malloc(strlen(word) + 1); // +1 is for "\0" Verify333(newstr != NULL); snprintf(newstr, strlen(word) +1, "%s", word); wp->word = newstr; // Set linkedlist from positions and append linked list wp->positions = AllocateLinkedList(); Verify333(wp->positions != NULL); retbool = AppendLinkedList(wp->positions, (LLPayload_t) ((intptr_t) pos)); Verify333(retbool); // Set the key value pair and add it to hashtable. kv.key = hashKey; kv.value = wp; retval = InsertHashTable(tab, kv, &oldkv); Verify333(retval == 1); } }