Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
Menu
Open sidebar
adam.huang
htop
Commits
a227b20f
Commit
a227b20f
authored
Apr 05, 2007
by
Hisham Muhammad
Browse files
Switch to unsigned keys in hash, according to issue #1688290
in the sf tracker
parent
e3198ca6
Changes
7
Show whitespace changes
Inline
Side-by-side
Hashtable.c
View file @
a227b20f
...
@@ -19,7 +19,7 @@ typedef struct Hashtable_ Hashtable;
...
@@ -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) {
...
@@ -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) {
...
@@ -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) {
...
@@ -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) {
...
@@ -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
)
{
...
...
Hashtable.h
View file @
a227b20f
...
@@ -21,7 +21,7 @@ typedef struct Hashtable_ Hashtable;
...
@@ -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);
...
@@ -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);
...
@@ -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
);
...
...
Process.c
View file @
a227b20f
...
@@ -50,16 +50,16 @@ typedef struct Process_ {
...
@@ -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) {
...
@@ -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
,
"%5
d
"
,
this
->
pid
);
break
;
case
PID
:
snprintf
(
buffer
,
n
,
"%5
u
"
,
this
->
pid
);
break
;
case
PPID
:
snprintf
(
buffer
,
n
,
"%5
d
"
,
this
->
ppid
);
break
;
case
PPID
:
snprintf
(
buffer
,
n
,
"%5
u
"
,
this
->
ppid
);
break
;
case
PGRP
:
snprintf
(
buffer
,
n
,
"%5
d
"
,
this
->
pgrp
);
break
;
case
PGRP
:
snprintf
(
buffer
,
n
,
"%5
u
"
,
this
->
pgrp
);
break
;
case
SESSION
:
snprintf
(
buffer
,
n
,
"%5
d
"
,
this
->
session
);
break
;
case
SESSION
:
snprintf
(
buffer
,
n
,
"%5
u
"
,
this
->
session
);
break
;
case
TTY_NR
:
snprintf
(
buffer
,
n
,
"%5
d
"
,
this
->
tty_nr
);
break
;
case
TTY_NR
:
snprintf
(
buffer
,
n
,
"%5
u
"
,
this
->
tty_nr
);
break
;
case
TPGID
:
snprintf
(
buffer
,
n
,
"%5
d
"
,
this
->
tpgid
);
break
;
case
TPGID
:
snprintf
(
buffer
,
n
,
"%5
u
"
,
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
)
{
...
...
ProcessList.c
View file @
a227b20f
...
@@ -312,7 +312,7 @@ void ProcessList_remove(ProcessList* this, Process* p) {
...
@@ -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
);
...
...
UsersTable.c
View file @
a227b20f
...
@@ -35,7 +35,7 @@ void UsersTable_delete(UsersTable* this) {
...
@@ -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
);
...
...
UsersTable.h
View file @
a227b20f
...
@@ -28,7 +28,7 @@ UsersTable* UsersTable_new();
...
@@ -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
);
...
...
htop.c
View file @
a227b20f
...
@@ -312,7 +312,7 @@ int main(int argc, char** argv) {
...
@@ -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) {
...
@@ -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
;
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment