windows porting changes
[csql.git] / src / server / BucketList.cxx
blob0af88af55efd4ea52f954a5e823c97167a7b7343
1 /***************************************************************************
2 * Copyright (C) 2007 by www.databasecache.com *
3 * Contact: praba_tuty@databasecache.com *
4 * *
5 * This program is free software; you can redistribute it and/or modify *
6 * it under the terms of the GNU General Public License as published by *
7 * the Free Software Foundation; either version 2 of the License, or *
8 * (at your option) any later version. *
9 * *
10 * This program is distributed in the hope that it will be useful, *
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13 * GNU General Public License for more details. *
14 * *
15 ***************************************************************************/
16 #include<Index.h>
17 #include<Allocator.h>
18 #include<Database.h>
19 #include<Debug.h>
20 DbRetVal BucketList::insert(Chunk *chunk, Database *db, void *key, void*tuple)
22 DbRetVal rv = OK;
23 HashIndexNode *newNode;// (HashIndexNode*) chunk->allocate(db, &rv);
24 newNode= (HashIndexNode*) chunk->allocate(db, &rv);
25 if (NULL == newNode)
27 printError(rv, "Unable to allocate HashIndex node");
28 return rv;
30 printDebug(DM_HashIndex,"Hash Index node allocated:%x", newNode);
31 newNode->ptrToKey_ = key;
32 newNode->ptrToTuple_ = tuple;
33 newNode->next_ = NULL;
35 //If this is the first node, set it as head
36 if (NULL == head)
38 printDebug(DM_HashIndex, "BucketList:insert head is null key:%x",key);
39 head = newNode;
40 return OK;
43 HashIndexNode *it = head;
44 while (NULL != it->next_) it = it->next_;
45 it->next_ = newNode;
46 printDebug(DM_HashIndex, "BucketList:insert adding it to the end of list key:%x", key);
47 return rv;
49 //Returns 2 if the head itself is removed.
50 DbRetVal BucketList::remove(Chunk *chunk, Database *db, void *keyPtr)
52 if (NULL == head) return ErrNotFound;
53 HashIndexNode *ite = head, *prev = head;
54 while (ite != NULL)
56 if (ite->ptrToKey_ == keyPtr)
58 prev->next_ = ite->next_;
59 chunk->free(db, ite);
60 if ( ite == head) { head = NULL; return SplCase; }
61 return OK;
63 prev = ite;
64 ite = ite->next_;
66 printError(ErrNotFound, "Node not found in the bucket list");
67 return ErrNotFound;