00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016 #include<Index.h>
00017 #include<Allocator.h>
00018 #include<Database.h>
00019 #include<Debug.h>
00020 DbRetVal BucketList::insert(Chunk *chunk, Database *db, void *key, void*tuple)
00021 {
00022 DbRetVal rv = OK;
00023 HashIndexNode *newNode;
00024 newNode= (HashIndexNode*) chunk->allocate(db, &rv);
00025 if (NULL == newNode)
00026 {
00027 printError(rv, "Unable to allocate HashIndex node");
00028 return rv;
00029 }
00030 printDebug(DM_HashIndex,"Hash Index node allocated:%x", newNode);
00031 newNode->ptrToKey_ = key;
00032 newNode->ptrToTuple_ = tuple;
00033 newNode->next_ = NULL;
00034
00035
00036 if (NULL == head)
00037 {
00038 printDebug(DM_HashIndex, "BucketList:insert head is null key:%x",key);
00039 head = newNode;
00040 return OK;
00041 }
00042
00043 HashIndexNode *it = head;
00044 while (NULL != it->next_) it = it->next_;
00045 it->next_ = newNode;
00046 printDebug(DM_HashIndex, "BucketList:insert adding it to the end of list key:%x", key);
00047 return rv;
00048 }
00049
00050 DbRetVal BucketList::remove(Chunk *chunk, Database *db, void *keyPtr)
00051 {
00052 if (NULL == head) return ErrNotFound;
00053 HashIndexNode *ite = head, *prev = head;
00054 while (ite != NULL)
00055 {
00056 if (ite->ptrToKey_ == keyPtr)
00057 {
00058 prev->next_ = ite->next_;
00059 chunk->free(db, ite);
00060 if ( ite == head) { head = NULL; return SplCase; }
00061 return OK;
00062 }
00063 prev = ite;
00064 ite = ite->next_;
00065 }
00066 printError(ErrNotFound, "Node not found in the bucket list");
00067 return ErrNotFound;
00068 }