Switch to unsigned keys in hash, according to issue #1688290

in the sf tracker
This commit is contained in:
Hisham Muhammad 2007-04-05 19:53:23 +00:00
parent e3198ca63b
commit a227b20fef
7 changed files with 30 additions and 30 deletions

View File

@ -19,7 +19,7 @@ typedef struct Hashtable_ Hashtable;
typedef void(*Hashtable_PairFunction)(int, void*, void*); typedef void(*Hashtable_PairFunction)(int, void*, void*);
typedef struct HashtableItem { typedef struct HashtableItem {
int key; unsigned int key;
void* value; void* value;
struct HashtableItem* next; struct HashtableItem* next;
} HashtableItem; } HashtableItem;
@ -61,7 +61,7 @@ int Hashtable_count(Hashtable* this) {
#endif #endif
HashtableItem* HashtableItem_new(int key, void* value) { HashtableItem* HashtableItem_new(unsigned int key, void* value) {
HashtableItem* this; HashtableItem* this;
this = (HashtableItem*) malloc(sizeof(HashtableItem)); this = (HashtableItem*) malloc(sizeof(HashtableItem));
@ -104,8 +104,8 @@ inline int Hashtable_size(Hashtable* this) {
return this->items; return this->items;
} }
void Hashtable_put(Hashtable* this, int key, void* value) { void Hashtable_put(Hashtable* this, unsigned int key, void* value) {
int index = key % this->size; unsigned int index = key % this->size;
HashtableItem** bucketPtr = &(this->buckets[index]); HashtableItem** bucketPtr = &(this->buckets[index]);
while (true) while (true)
if (*bucketPtr == NULL) { if (*bucketPtr == NULL) {
@ -122,8 +122,8 @@ void Hashtable_put(Hashtable* this, int key, void* value) {
assert(Hashtable_isConsistent(this)); assert(Hashtable_isConsistent(this));
} }
void* Hashtable_remove(Hashtable* this, int key) { void* Hashtable_remove(Hashtable* this, unsigned int key) {
int index = key % this->size; unsigned int index = key % this->size;
assert(Hashtable_isConsistent(this)); assert(Hashtable_isConsistent(this));
@ -149,8 +149,8 @@ void* Hashtable_remove(Hashtable* this, int key) {
return NULL; return NULL;
} }
inline void* Hashtable_get(Hashtable* this, int key) { inline void* Hashtable_get(Hashtable* this, unsigned int key) {
int index = key % this->size; unsigned int index = key % this->size;
HashtableItem* bucketPtr = this->buckets[index]; HashtableItem* bucketPtr = this->buckets[index];
while (true) { while (true) {
if (bucketPtr == NULL) { if (bucketPtr == NULL) {

View File

@ -21,7 +21,7 @@ typedef struct Hashtable_ Hashtable;
typedef void(*Hashtable_PairFunction)(int, void*, void*); typedef void(*Hashtable_PairFunction)(int, void*, void*);
typedef struct HashtableItem { typedef struct HashtableItem {
int key; unsigned int key;
void* value; void* value;
struct HashtableItem* next; struct HashtableItem* next;
} HashtableItem; } HashtableItem;
@ -41,7 +41,7 @@ int Hashtable_count(Hashtable* this);
#endif #endif
HashtableItem* HashtableItem_new(int key, void* value); HashtableItem* HashtableItem_new(unsigned int key, void* value);
Hashtable* Hashtable_new(int size, bool owner); Hashtable* Hashtable_new(int size, bool owner);
@ -49,11 +49,11 @@ void Hashtable_delete(Hashtable* this);
inline int Hashtable_size(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); void Hashtable_foreach(Hashtable* this, Hashtable_PairFunction f, void* userData);

View File

@ -50,16 +50,16 @@ typedef struct Process_ {
struct ProcessList_ *pl; struct ProcessList_ *pl;
bool updated; bool updated;
int pid; unsigned int pid;
char* comm; char* comm;
int indent; int indent;
char state; char state;
bool tag; bool tag;
int ppid; unsigned int ppid;
int pgrp; unsigned int pgrp;
int session; unsigned int session;
int tty_nr; unsigned int tty_nr;
int tpgid; unsigned int tpgid;
unsigned long int flags; unsigned long int flags;
#ifdef DEBUG #ifdef DEBUG
unsigned long int minflt; unsigned long int minflt;
@ -261,12 +261,12 @@ void Process_writeField(Process* this, RichString* str, ProcessField field) {
int n = PROCESS_COMM_LEN; int n = PROCESS_COMM_LEN;
switch (field) { switch (field) {
case PID: snprintf(buffer, n, "%5d ", this->pid); break; case PID: snprintf(buffer, n, "%5u ", this->pid); break;
case PPID: snprintf(buffer, n, "%5d ", this->ppid); break; case PPID: snprintf(buffer, n, "%5u ", this->ppid); break;
case PGRP: snprintf(buffer, n, "%5d ", this->pgrp); break; case PGRP: snprintf(buffer, n, "%5u ", this->pgrp); break;
case SESSION: snprintf(buffer, n, "%5d ", this->session); break; case SESSION: snprintf(buffer, n, "%5u ", this->session); break;
case TTY_NR: snprintf(buffer, n, "%5d ", this->tty_nr); break; case TTY_NR: snprintf(buffer, n, "%5u ", this->tty_nr); break;
case TPGID: snprintf(buffer, n, "%5d ", this->tpgid); break; case TPGID: snprintf(buffer, n, "%5u ", this->tpgid); break;
case PROCESSOR: snprintf(buffer, n, "%3d ", this->processor+1); break; case PROCESSOR: snprintf(buffer, n, "%3d ", this->processor+1); break;
case COMM: { case COMM: {
if (!this->pl->treeView || this->indent == 0) { if (!this->pl->treeView || this->indent == 0) {

View File

@ -312,7 +312,7 @@ void ProcessList_remove(ProcessList* this, Process* p) {
assert(Hashtable_get(this->processTable, p->pid) != NULL); assert(Hashtable_get(this->processTable, p->pid) != NULL);
Process* pp = Hashtable_remove(this->processTable, p->pid); Process* pp = Hashtable_remove(this->processTable, p->pid);
assert(pp == p); (void)pp; assert(pp == p); (void)pp;
int pid = p->pid; unsigned int pid = p->pid;
int index = Vector_indexOf(this->processes, p, Process_pidCompare); int index = Vector_indexOf(this->processes, p, Process_pidCompare);
assert(index != -1); assert(index != -1);
Vector_remove(this->processes, index); Vector_remove(this->processes, index);

View File

@ -35,7 +35,7 @@ void UsersTable_delete(UsersTable* this) {
free(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)); char* name = (char*) (Hashtable_get(this->users, uid));
if (name == NULL) { if (name == NULL) {
struct passwd* userData = getpwuid(uid); struct passwd* userData = getpwuid(uid);

View File

@ -28,7 +28,7 @@ UsersTable* UsersTable_new();
void UsersTable_delete(UsersTable* this); 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); inline int UsersTable_size(UsersTable* this);

4
htop.c
View File

@ -312,7 +312,7 @@ int main(int argc, char** argv) {
incSearchIndex = 0; incSearchIndex = 0;
incSearchBuffer[0] = 0; incSearchBuffer[0] = 0;
int currPos = Panel_getSelectedIndex(panel); int currPos = Panel_getSelectedIndex(panel);
int currPid = 0; unsigned int currPid = 0;
int currScrollV = panel->scrollV; int currScrollV = panel->scrollV;
if (follow) if (follow)
currPid = ProcessList_get(pl, currPos)->pid; currPid = ProcessList_get(pl, currPos)->pid;
@ -406,7 +406,7 @@ int main(int argc, char** argv) {
continue; continue;
} }
if (isdigit((char)ch)) { 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++) for (int i = 0; i < ProcessList_size(pl) && ((Process*) Panel_getSelected(panel))->pid != pid; i++)
Panel_setSelected(panel, i); Panel_setSelected(panel, i);
acc = pid * 10; acc = pid * 10;