src/server/BucketList.cxx

Go to the documentation of this file.
00001 /***************************************************************************
00002  *   Copyright (C) 2007 by www.databasecache.com                           *
00003  *   Contact: praba_tuty@databasecache.com                                 *
00004  *                                                                         *
00005  *   This program is free software; you can redistribute it and/or modify  *
00006  *   it under the terms of the GNU General Public License as published by  *
00007  *   the Free Software Foundation; either version 2 of the License, or     *
00008  *   (at your option) any later version.                                   *
00009  *                                                                         *
00010  *   This program is distributed in the hope that it will be useful,       *
00011  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
00012  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
00013  *   GNU General Public License for more details.                          *
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;// (HashIndexNode*) chunk->allocate(db, &rv);
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     //If this is the first node, set it as head
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 //Returns 2 if the head itself is removed.
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 }

Generated on Mon Jun 9 22:37:15 2008 for csql by  doxygen 1.4.7