summaryrefslogtreecommitdiffstats
path: root/Hashtable.c
diff options
context:
space:
mode:
authorHisham Muhammad <hisham@gobolinux.org>2006-07-12 01:16:03 +0000
committerHisham Muhammad <hisham@gobolinux.org>2006-07-12 01:16:03 +0000
commitdbe2670b69e163cb146d3fc3b3c7b82ea3f71278 (patch)
tree6c9163067c52e387b24593f545fa2c549e4b4acf /Hashtable.c
parente46f1426b906433c291de05432de9a9a43e14f4a (diff)
Perform RichString operations by hand.
Avoid unnecessary operations when processing entries on ProcessList.
Diffstat (limited to 'Hashtable.c')
-rw-r--r--Hashtable.c13
1 files changed, 3 insertions, 10 deletions
diff --git a/Hashtable.c b/Hashtable.c
index f971c8c2..30218a52 100644
--- a/Hashtable.c
+++ b/Hashtable.c
@@ -16,7 +16,6 @@ in the source distribution for its full text.
typedef struct Hashtable_ Hashtable;
typedef void(*Hashtable_PairFunction)(int, void*, void*);
-typedef int(*Hashtable_HashAlgorithm)(Hashtable*, int);
typedef struct HashtableItem {
int key;
@@ -28,7 +27,6 @@ struct Hashtable_ {
int size;
HashtableItem** buckets;
int items;
- Hashtable_HashAlgorithm hashAlgorithm;
bool owner;
};
}*/
@@ -49,15 +47,10 @@ Hashtable* Hashtable_new(int size, bool owner) {
this = (Hashtable*) malloc(sizeof(Hashtable));
this->size = size;
this->buckets = (HashtableItem**) calloc(sizeof(HashtableItem*), size);
- this->hashAlgorithm = Hashtable_hashAlgorithm;
this->owner = owner;
return this;
}
-int Hashtable_hashAlgorithm(Hashtable* this, int key) {
- return key % this->size;
-}
-
void Hashtable_delete(Hashtable* this) {
for (int i = 0; i < this->size; i++) {
HashtableItem* walk = this->buckets[i];
@@ -78,7 +71,7 @@ inline int Hashtable_size(Hashtable* this) {
}
void Hashtable_put(Hashtable* this, int key, void* value) {
- int index = this->hashAlgorithm(this, key);
+ int index = key % this->size;
HashtableItem** bucketPtr = &(this->buckets[index]);
while (true)
if (*bucketPtr == NULL) {
@@ -95,7 +88,7 @@ void Hashtable_put(Hashtable* this, int key, void* value) {
}
void* Hashtable_remove(Hashtable* this, int key) {
- int index = this->hashAlgorithm(this, key);
+ int index = key % this->size;
HashtableItem** bucketPtr = &(this->buckets[index]);
while (true)
if (*bucketPtr == NULL) {
@@ -118,7 +111,7 @@ void* Hashtable_remove(Hashtable* this, int key) {
}
//#include <stdio.h>
inline void* Hashtable_get(Hashtable* this, int key) {
- int index = this->hashAlgorithm(this, key);
+ int index = key % this->size;
HashtableItem* bucketPtr = this->buckets[index];
// fprintf(stderr, "%d -> %d\n", key, index);
while (true) {

© 2014-2024 Faster IT GmbH | imprint | privacy policy