From a227b20fefda7d14316523ddd3aa1ce2b439169c Mon Sep 17 00:00:00 2001 From: Hisham Muhammad Date: Thu, 5 Apr 2007 19:53:23 +0000 Subject: Switch to unsigned keys in hash, according to issue #1688290 in the sf tracker --- Hashtable.c | 16 ++++++++-------- Hashtable.h | 10 +++++----- Process.c | 24 ++++++++++++------------ ProcessList.c | 2 +- UsersTable.c | 2 +- UsersTable.h | 2 +- htop.c | 4 ++-- 7 files changed, 30 insertions(+), 30 deletions(-) diff --git a/Hashtable.c b/Hashtable.c index 4cd63109..cfd14704 100644 --- a/Hashtable.c +++ b/Hashtable.c @@ -19,7 +19,7 @@ typedef struct Hashtable_ Hashtable; typedef void(*Hashtable_PairFunction)(int, void*, void*); typedef struct HashtableItem { - int key; + unsigned int key; void* value; struct HashtableItem* next; } HashtableItem; @@ -61,7 +61,7 @@ int Hashtable_count(Hashtable* this) { #endif -HashtableItem* HashtableItem_new(int key, void* value) { +HashtableItem* HashtableItem_new(unsigned int key, void* value) { HashtableItem* this; this = (HashtableItem*) malloc(sizeof(HashtableItem)); @@ -104,8 +104,8 @@ inline int Hashtable_size(Hashtable* this) { return this->items; } -void Hashtable_put(Hashtable* this, int key, void* value) { - int index = key % this->size; +void Hashtable_put(Hashtable* this, unsigned int key, void* value) { + unsigned int index = key % this->size; HashtableItem** bucketPtr = &(this->buckets[index]); while (true) if (*bucketPtr == NULL) { @@ -122,8 +122,8 @@ void Hashtable_put(Hashtable* this, int key, void* value) { assert(Hashtable_isConsistent(this)); } -void* Hashtable_remove(Hashtable* this, int key) { - int index = key % this->size; +void* Hashtable_remove(Hashtable* this, unsigned int key) { + unsigned int index = key % this->size; assert(Hashtable_isConsistent(this)); @@ -149,8 +149,8 @@ void* Hashtable_remove(Hashtable* this, int key) { return NULL; } -inline void* Hashtable_get(Hashtable* this, int key) { - int index = key % this->size; +inline void* Hashtable_get(Hashtable* this, unsigned int key) { + unsigned int index = key % this->size; HashtableItem* bucketPtr = this->buckets[index]; while (true) { if (bucketPtr == NULL) { diff --git a/Hashtable.h b/Hashtable.h index 7c1a6789..21dfdcc6 100644 --- a/Hashtable.h +++ b/Hashtable.h @@ -21,7 +21,7 @@ typedef struct Hashtable_ Hashtable; typedef void(*Hashtable_PairFunction)(int, void*, void*); typedef struct HashtableItem { - int key; + unsigned int key; void* value; struct HashtableItem* next; } HashtableItem; @@ -41,7 +41,7 @@ int Hashtable_count(Hashtable* this); #endif -HashtableItem* HashtableItem_new(int key, void* value); +HashtableItem* HashtableItem_new(unsigned int key, void* value); Hashtable* Hashtable_new(int size, bool owner); @@ -49,11 +49,11 @@ void Hashtable_delete(Hashtable* this); inline int Hashtable_size(Hashtable* this); -void Hashtable_put(Hashtable* this, int key, void* value); +void Hashtable_put(Hashtable* this, unsigned int key, void* value); -void* Hashtable_remove(Hashtable* this, int key); +void* Hashtable_remove(Hashtable* this, unsigned int key); -inline void* Hashtable_get(Hashtable* this, int key); +inline void* Hashtable_get(Hashtable* this, unsigned int key); void Hashtable_foreach(Hashtable* this, Hashtable_PairFunction f, void* userData); diff --git a/Process.c b/Process.c index 78688e24..6bfd2de9 100644 --- a/Process.c +++ b/Process.c @@ -50,16 +50,16 @@ typedef struct Process_ { struct ProcessList_ *pl; bool updated; - int pid; + unsigned int pid; char* comm; int indent; char state; bool tag; - int ppid; - int pgrp; - int session; - int tty_nr; - int tpgid; + unsigned int ppid; + unsigned int pgrp; + unsigned int session; + unsigned int tty_nr; + unsigned int tpgid; unsigned long int flags; #ifdef DEBUG unsigned long int minflt; @@ -261,12 +261,12 @@ void Process_writeField(Process* this, RichString* str, ProcessField field) { int n = PROCESS_COMM_LEN; switch (field) { - case PID: snprintf(buffer, n, "%5d ", this->pid); break; - case PPID: snprintf(buffer, n, "%5d ", this->ppid); break; - case PGRP: snprintf(buffer, n, "%5d ", this->pgrp); break; - case SESSION: snprintf(buffer, n, "%5d ", this->session); break; - case TTY_NR: snprintf(buffer, n, "%5d ", this->tty_nr); break; - case TPGID: snprintf(buffer, n, "%5d ", this->tpgid); break; + case PID: snprintf(buffer, n, "%5u ", this->pid); break; + case PPID: snprintf(buffer, n, "%5u ", this->ppid); break; + case PGRP: snprintf(buffer, n, "%5u ", this->pgrp); break; + case SESSION: snprintf(buffer, n, "%5u ", this->session); break; + case TTY_NR: snprintf(buffer, n, "%5u ", this->tty_nr); break; + case TPGID: snprintf(buffer, n, "%5u ", this->tpgid); break; case PROCESSOR: snprintf(buffer, n, "%3d ", this->processor+1); break; case COMM: { if (!this->pl->treeView || this->indent == 0) { diff --git a/ProcessList.c b/ProcessList.c index b7f52a2f..281d9df0 100644 --- a/ProcessList.c +++ b/ProcessList.c @@ -312,7 +312,7 @@ void ProcessList_remove(ProcessList* this, Process* p) { assert(Hashtable_get(this->processTable, p->pid) != NULL); Process* pp = Hashtable_remove(this->processTable, p->pid); assert(pp == p); (void)pp; - int pid = p->pid; + unsigned int pid = p->pid; int index = Vector_indexOf(this->processes, p, Process_pidCompare); assert(index != -1); Vector_remove(this->processes, index); diff --git a/UsersTable.c b/UsersTable.c index f738334e..ca33779c 100644 --- a/UsersTable.c +++ b/UsersTable.c @@ -35,7 +35,7 @@ void UsersTable_delete(UsersTable* this) { free(this); } -char* UsersTable_getRef(UsersTable* this, int uid) { +char* UsersTable_getRef(UsersTable* this, unsigned int uid) { char* name = (char*) (Hashtable_get(this->users, uid)); if (name == NULL) { struct passwd* userData = getpwuid(uid); diff --git a/UsersTable.h b/UsersTable.h index 54b997dc..7f6740eb 100644 --- a/UsersTable.h +++ b/UsersTable.h @@ -28,7 +28,7 @@ UsersTable* UsersTable_new(); void UsersTable_delete(UsersTable* this); -char* UsersTable_getRef(UsersTable* this, int uid); +char* UsersTable_getRef(UsersTable* this, unsigned int uid); inline int UsersTable_size(UsersTable* this); diff --git a/htop.c b/htop.c index 3fb72c98..96e01060 100644 --- a/htop.c +++ b/htop.c @@ -312,7 +312,7 @@ int main(int argc, char** argv) { incSearchIndex = 0; incSearchBuffer[0] = 0; int currPos = Panel_getSelectedIndex(panel); - int currPid = 0; + unsigned int currPid = 0; int currScrollV = panel->scrollV; if (follow) currPid = ProcessList_get(pl, currPos)->pid; @@ -406,7 +406,7 @@ int main(int argc, char** argv) { continue; } if (isdigit((char)ch)) { - int pid = ch-48 + acc; + unsigned int pid = ch-48 + acc; for (int i = 0; i < ProcessList_size(pl) && ((Process*) Panel_getSelected(panel))->pid != pid; i++) Panel_setSelected(panel, i); acc = pid * 10; -- cgit v1.2.3