mirror of https://github.com/xzeldon/htop.git
Switch to unsigned keys in hash, according to issue #1688290
in the sf tracker
This commit is contained in:
parent
e3198ca63b
commit
a227b20fef
16
Hashtable.c
16
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) {
|
||||
|
|
10
Hashtable.h
10
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);
|
||||
|
||||
|
|
24
Process.c
24
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) {
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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);
|
||||
|
||||
|
|
4
htop.c
4
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;
|
||||
|
|
Loading…
Reference in New Issue