projects
/
citadel.git
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
|
inline
| side by side (parent:
16df94f
)
* typo in varname
author
Wilfried Göesgens
<willi@citadel.org>
Sun, 6 Dec 2009 21:36:00 +0000
(21:36 +0000)
committer
Wilfried Göesgens
<willi@citadel.org>
Sun, 6 Dec 2009 21:36:00 +0000
(21:36 +0000)
libcitadel/lib/hash.c
patch
|
blob
|
history
diff --git
a/libcitadel/lib/hash.c
b/libcitadel/lib/hash.c
index 066675b8372c0baf1a807904738e13d3ca751618..2eb5e1a0d11f77834c4a7c55f949dcf42d8bdbe7 100644
(file)
--- a/
libcitadel/lib/hash.c
+++ b/
libcitadel/lib/hash.c
@@
-37,7
+37,7
@@
struct HashList {
char **MyKeys; /**< this keeps the members for a call of GetHashKeys */
HashFunc Algorithm; /**< should we use an alternating algorithm to calc the hash values? */
long nMembersUsed; /**< how many pointers inside of the array are used? */
char **MyKeys; /**< this keeps the members for a call of GetHashKeys */
HashFunc Algorithm; /**< should we use an alternating algorithm to calc the hash values? */
long nMembersUsed; /**< how many pointers inside of the array are used? */
- long nLookpTableItems; /**< how many items of the lookup table are used? */
+ long nLook
u
pTableItems; /**< how many items of the lookup table are used? */
long MemberSize; /**< how big is Members and LookupTable? */
long tainted; /**< if 0, we're hashed, else s.b. else sorted us in his own way. */
long uniq; /**< are the keys going to be uniq? */
long MemberSize; /**< how big is Members and LookupTable? */
long tainted; /**< if 0, we're hashed, else s.b. else sorted us in his own way. */
long uniq; /**< are the keys going to be uniq? */
@@
-70,7
+70,7
@@
int PrintHash(HashList *Hash, TransitionFunc Trans, PrintHashDataFunc PrintEntry
if (Hash == NULL)
return 0;
if (Hash == NULL)
return 0;
- for (i=0; i < Hash->nLookpTableItems; i++) {
+ for (i=0; i < Hash->nLook
u
pTableItems; i++) {
if (i==0) {
Previous = NULL;
}
if (i==0) {
Previous = NULL;
}
@@
-117,11
+117,11
@@
int dbg_PrintHash(HashList *Hash, PrintHashContent First, PrintHashContent Secon
if (Hash->MyKeys != NULL)
free (Hash->MyKeys);
if (Hash->MyKeys != NULL)
free (Hash->MyKeys);
- Hash->MyKeys = (char**) malloc(sizeof(char*) * Hash->nLookpTableItems);
+ Hash->MyKeys = (char**) malloc(sizeof(char*) * Hash->nLook
u
pTableItems);
#ifdef DEBUG
printf("----------------------------------\n");
#endif
#ifdef DEBUG
printf("----------------------------------\n");
#endif
- for (i=0; i < Hash->nLookpTableItems; i++) {
+ for (i=0; i < Hash->nLook
u
pTableItems; i++) {
if (Hash->LookupTable[i] == NULL)
{
if (Hash->LookupTable[i] == NULL)
{
@@
-180,7
+180,7
@@
HashList *NewHash(int Uniq, HashFunc F)
int GetCount(HashList *Hash)
{
if(Hash==NULL) return 0;
int GetCount(HashList *Hash)
{
if(Hash==NULL) return 0;
- return Hash->nLookpTableItems;
+ return Hash->nLook
u
pTableItems;
}
}
@@
-261,9
+261,9
@@
static void IncreaseHashSize(HashList *Hash)
return ;
/** If we grew to much, this might be the place to rehash and shrink again.
return ;
/** If we grew to much, this might be the place to rehash and shrink again.
- if ((Hash->NMembersUsed > Hash->nLookpTableItems) &&
- ((Hash->NMembersUsed - Hash->nLookpTableItems) >
- (Hash->nLookpTableItems / 10)))
+ if ((Hash->NMembersUsed > Hash->nLook
u
pTableItems) &&
+ ((Hash->NMembersUsed - Hash->nLook
u
pTableItems) >
+ (Hash->nLook
u
pTableItems / 10)))
{
{
@@
-329,11
+329,11
@@
static void InsertHashItem(HashList *Hash,
/** our payload is queued at the end... */
NewHashKey->Position = Hash->nMembersUsed;
/** but if we should be sorted into a specific place... */
/** our payload is queued at the end... */
NewHashKey->Position = Hash->nMembersUsed;
/** but if we should be sorted into a specific place... */
- if ((Hash->nLookpTableItems != 0) &&
- (HashPos != Hash->nLookpTableItems) ) {
+ if ((Hash->nLook
u
pTableItems != 0) &&
+ (HashPos != Hash->nLook
u
pTableItems) ) {
long ItemsAfter;
long ItemsAfter;
- ItemsAfter = Hash->nLookpTableItems - HashPos;
+ ItemsAfter = Hash->nLook
u
pTableItems - HashPos;
/** make space were we can fill us in */
if (ItemsAfter > 0)
{
/** make space were we can fill us in */
if (ItemsAfter > 0)
{
@@
-346,7
+346,7
@@
static void InsertHashItem(HashList *Hash,
Hash->Members[Hash->nMembersUsed] = NewPayloadItem;
Hash->LookupTable[HashPos] = NewHashKey;
Hash->nMembersUsed++;
Hash->Members[Hash->nMembersUsed] = NewPayloadItem;
Hash->LookupTable[HashPos] = NewHashKey;
Hash->nMembersUsed++;
- Hash->nLookpTableItems++;
+ Hash->nLook
u
pTableItems++;
}
/**
}
/**
@@
-363,7
+363,7
@@
static long FindInTaintedHash(HashList *Hash, long HashBinKey)
if (Hash == NULL)
return 0;
if (Hash == NULL)
return 0;
- for (SearchPos = 0; SearchPos < Hash->nLookpTableItems; SearchPos ++) {
+ for (SearchPos = 0; SearchPos < Hash->nLook
u
pTableItems; SearchPos ++) {
if (Hash->LookupTable[SearchPos]->Key == HashBinKey){
return SearchPos;
}
if (Hash->LookupTable[SearchPos]->Key == HashBinKey){
return SearchPos;
}
@@
-388,10
+388,10
@@
static long FindInHash(HashList *Hash, long HashBinKey)
if (Hash->tainted)
return FindInTaintedHash(Hash, HashBinKey);
if (Hash->tainted)
return FindInTaintedHash(Hash, HashBinKey);
- SearchPos = Hash->nLookpTableItems / 2;
+ SearchPos = Hash->nLook
u
pTableItems / 2;
StepWidth = SearchPos / 2;
while ((SearchPos > 0) &&
StepWidth = SearchPos / 2;
while ((SearchPos > 0) &&
- (SearchPos < Hash->nLookpTableItems))
+ (SearchPos < Hash->nLook
u
pTableItems))
{
/** Did we find it? */
if (Hash->LookupTable[SearchPos]->Key == HashBinKey){
{
/** Did we find it? */
if (Hash->LookupTable[SearchPos]->Key == HashBinKey){
@@
-413,7
+413,7
@@
static long FindInHash(HashList *Hash, long HashBinKey)
SearchPos --;
}
else {
SearchPos --;
}
else {
- if ((SearchPos + 1 < Hash->nLookpTableItems) &&
+ if ((SearchPos + 1 < Hash->nLook
u
pTableItems) &&
(Hash->LookupTable[SearchPos + 1]->Key > HashBinKey))
return SearchPos;
SearchPos ++;
(Hash->LookupTable[SearchPos + 1]->Key > HashBinKey))
return SearchPos;
SearchPos ++;
@@
-528,7
+528,7
@@
int GetHash(HashList *Hash, const char *HKey, long HKLen, void **Data)
HashBinKey = CalcHashKey(Hash, HKey, HKLen);
HashAt = FindInHash(Hash, HashBinKey);
if ((HashAt < 0) || /**< Not found at the lower edge? */
HashBinKey = CalcHashKey(Hash, HKey, HKLen);
HashAt = FindInHash(Hash, HashBinKey);
if ((HashAt < 0) || /**< Not found at the lower edge? */
- (HashAt >= Hash->nLookpTableItems) || /**< Not found at the upper edge? */
+ (HashAt >= Hash->nLook
u
pTableItems) || /**< Not found at the upper edge? */
(Hash->LookupTable[HashAt]->Key != HashBinKey)) { /**< somewhere inbetween but no match? */
*Data = NULL;
return 0;
(Hash->LookupTable[HashAt]->Key != HashBinKey)) { /**< somewhere inbetween but no match? */
*Data = NULL;
return 0;
@@
-562,13
+562,13
@@
int GetHashKeys(HashList *Hash, char ***List)
if (Hash->MyKeys != NULL)
free (Hash->MyKeys);
if (Hash->MyKeys != NULL)
free (Hash->MyKeys);
- Hash->MyKeys = (char**) malloc(sizeof(char*) * Hash->nLookpTableItems);
- for (i=0; i < Hash->nLookpTableItems; i++) {
+ Hash->MyKeys = (char**) malloc(sizeof(char*) * Hash->nLook
u
pTableItems);
+ for (i=0; i < Hash->nLook
u
pTableItems; i++) {
Hash->MyKeys[i] = Hash->LookupTable[i]->HashKey;
}
*List = (char**)Hash->MyKeys;
Hash->MyKeys[i] = Hash->LookupTable[i]->HashKey;
}
*List = (char**)Hash->MyKeys;
- return Hash->nLookpTableItems;
+ return Hash->nLook
u
pTableItems;
}
/**
}
/**
@@
-589,7
+589,7
@@
HashPos *GetNewHashPos(HashList *Hash, int StepWidth)
else
Ret->StepWidth = 1;
if (Ret->StepWidth < 0) {
else
Ret->StepWidth = 1;
if (Ret->StepWidth < 0) {
- Ret->Position = Hash->nLookpTableItems - 1;
+ Ret->Position = Hash->nLook
u
pTableItems - 1;
}
else {
Ret->Position = 0;
}
else {
Ret->Position = 0;
@@
-620,7
+620,7
@@
int GetHashPosFromKey(HashList *Hash, const char *HKey, long HKLen, HashPos *At)
HashBinKey = CalcHashKey(Hash, HKey, HKLen);
HashAt = FindInHash(Hash, HashBinKey);
if ((HashAt < 0) || /**< Not found at the lower edge? */
HashBinKey = CalcHashKey(Hash, HKey, HKLen);
HashAt = FindInHash(Hash, HashBinKey);
if ((HashAt < 0) || /**< Not found at the lower edge? */
- (HashAt >= Hash->nLookpTableItems) || /**< Not found at the upper edge? */
+ (HashAt >= Hash->nLook
u
pTableItems) || /**< Not found at the upper edge? */
(Hash->LookupTable[HashAt]->Key != HashBinKey)) { /**< somewhere inbetween but no match? */
return 0;
}
(Hash->LookupTable[HashAt]->Key != HashBinKey)) { /**< somewhere inbetween but no match? */
return 0;
}
@@
-643,9
+643,9
@@
int DeleteEntryFromHash(HashList *Hash, HashPos *At)
/* if lockable, lock here */
if ((Hash == NULL) ||
/* if lockable, lock here */
if ((Hash == NULL) ||
- (At->Position >= Hash->nLookpTableItems) ||
+ (At->Position >= Hash->nLook
u
pTableItems) ||
(At->Position < 0) ||
(At->Position < 0) ||
- (At->Position > Hash->nLookpTableItems))
+ (At->Position > Hash->nLook
u
pTableItems))
{
/* unlock... */
return 0;
{
/* unlock... */
return 0;
@@
-660,17
+660,17
@@
int DeleteEntryFromHash(HashList *Hash, HashPos *At)
{
free(Hash->LookupTable[At->Position]->HashKey);
free(Hash->LookupTable[At->Position]);
{
free(Hash->LookupTable[At->Position]->HashKey);
free(Hash->LookupTable[At->Position]);
- if (At->Position < Hash->nLookpTableItems)
+ if (At->Position < Hash->nLook
u
pTableItems)
{
memmove(&Hash->LookupTable[At->Position],
&Hash->LookupTable[At->Position + 1],
{
memmove(&Hash->LookupTable[At->Position],
&Hash->LookupTable[At->Position + 1],
- (Hash->nLookpTableItems - At->Position - 1) *
+ (Hash->nLook
u
pTableItems - At->Position - 1) *
sizeof(HashKey*));
}
else
Hash->LookupTable[At->Position] = NULL;
sizeof(HashKey*));
}
else
Hash->LookupTable[At->Position] = NULL;
- Hash->nLookpTableItems--;
+ Hash->nLook
u
pTableItems--;
}
/* unlock... */
}
/* unlock... */
@@
-692,9
+692,9
@@
int DeleteEntryFromHash(HashList *Hash, HashPos *At)
int GetHashPosCounter(HashList *Hash, HashPos *At)
{
if ((Hash == NULL) ||
int GetHashPosCounter(HashList *Hash, HashPos *At)
{
if ((Hash == NULL) ||
- (At->Position >= Hash->nLookpTableItems) ||
+ (At->Position >= Hash->nLook
u
pTableItems) ||
(At->Position < 0) ||
(At->Position < 0) ||
- (At->Position > Hash->nLookpTableItems))
+ (At->Position > Hash->nLook
u
pTableItems))
return 0;
return At->Position;
}
return 0;
return At->Position;
}
@@
-725,9
+725,9
@@
int GetNextHashPos(HashList *Hash, HashPos *At, long *HKLen, const char **HashKe
long PayloadPos;
if ((Hash == NULL) ||
long PayloadPos;
if ((Hash == NULL) ||
- (At->Position >= Hash->nLookpTableItems) ||
+ (At->Position >= Hash->nLook
u
pTableItems) ||
(At->Position < 0) ||
(At->Position < 0) ||
- (At->Position > Hash->nLookpTableItems))
+ (At->Position > Hash->nLook
u
pTableItems))
return 0;
*HKLen = Hash->LookupTable[At->Position]->HKLen;
*HashKey = Hash->LookupTable[At->Position]->HashKey;
return 0;
*HKLen = Hash->LookupTable[At->Position]->HKLen;
*HashKey = Hash->LookupTable[At->Position]->HashKey;
@@
-758,7
+758,7
@@
int GetHashAt(HashList *Hash,long At, long *HKLen, const char **HashKey, void **
if ((Hash == NULL) ||
(At < 0) ||
if ((Hash == NULL) ||
(At < 0) ||
- (At > Hash->nLookpTableItems))
+ (At > Hash->nLook
u
pTableItems))
return 0;
*HKLen = Hash->LookupTable[At]->HKLen;
*HashKey = Hash->LookupTable[At]->HashKey;
return 0;
*HKLen = Hash->LookupTable[At]->HKLen;
*HashKey = Hash->LookupTable[At]->HashKey;
@@
-781,7
+781,7
@@
long GetHashIDAt(HashList *Hash,long At)
{
if ((Hash == NULL) ||
(At < 0) ||
{
if ((Hash == NULL) ||
(At < 0) ||
- (At > Hash->nLookpTableItems))
+ (At > Hash->nLook
u
pTableItems))
return 0;
return Hash->LookupTable[At]->Key;
return 0;
return Hash->LookupTable[At]->Key;
@@
-841,9
+841,9
@@
static int SortByHashKeys(const void *Key1, const void* Key2)
*/
void SortByHashKey(HashList *Hash, int Order)
{
*/
void SortByHashKey(HashList *Hash, int Order)
{
- if (Hash->nLookpTableItems < 2)
+ if (Hash->nLook
u
pTableItems < 2)
return;
return;
- qsort(Hash->LookupTable, Hash->nLookpTableItems, sizeof(HashKey*),
+ qsort(Hash->LookupTable, Hash->nLook
u
pTableItems, sizeof(HashKey*),
(Order)?SortByKeys:SortByKeysRev);
Hash->tainted = 1;
}
(Order)?SortByKeys:SortByKeysRev);
Hash->tainted = 1;
}
@@
-856,9
+856,9
@@
void SortByHashKey(HashList *Hash, int Order)
void SortByHashKeyStr(HashList *Hash)
{
Hash->tainted = 0;
void SortByHashKeyStr(HashList *Hash)
{
Hash->tainted = 0;
- if (Hash->nLookpTableItems < 2)
+ if (Hash->nLook
u
pTableItems < 2)
return;
return;
- qsort(Hash->LookupTable, Hash->nLookpTableItems, sizeof(HashKey*), SortByHashKeys);
+ qsort(Hash->LookupTable, Hash->nLook
u
pTableItems, sizeof(HashKey*), SortByHashKeys);
}
}
@@
-880,9
+880,9
@@
const void *GetSearchPayload(const void *HashVoid)
*/
void SortByPayload(HashList *Hash, CompareFunc SortBy)
{
*/
void SortByPayload(HashList *Hash, CompareFunc SortBy)
{
- if (Hash->nLookpTableItems < 2)
+ if (Hash->nLook
u
pTableItems < 2)
return;
return;
- qsort(Hash->LookupTable, Hash->nLookpTableItems, sizeof(HashKey*), SortBy);
+ qsort(Hash->LookupTable, Hash->nLook
u
pTableItems, sizeof(HashKey*), SortBy);
Hash->tainted = 1;
}
Hash->tainted = 1;
}