aboutsummaryrefslogtreecommitdiff
path: root/hashtable.c
diff options
context:
space:
mode:
authormescalinum <mescalinum@users.sourceforge.net>2011-10-28 19:25:27 +0000
committermescalinum <mescalinum@users.sourceforge.net>2011-10-28 19:25:27 +0000
commit30fb06bce3c76c7f37d8649aa33927f38ed194a9 (patch)
tree83783794bfe5f28afcb94731de53b88eabcb436e /hashtable.c
parent7376fa909b828167badf549834f532046ada066d (diff)
add open menu
svn path=/trunk/externals/loaders/tclpd/; revision=15671
Diffstat (limited to 'hashtable.c')
-rw-r--r--hashtable.c17
1 files changed, 14 insertions, 3 deletions
diff --git a/hashtable.c b/hashtable.c
index 0b4409f..c2fa96f 100644
--- a/hashtable.c
+++ b/hashtable.c
@@ -15,19 +15,27 @@ uint32_t hash_str(const char *s) {
list_node_t* list_add(list_node_t* head, const char* k, void* v) {
list_node_t* n = (list_node_t*)malloc(sizeof(list_node_t));
n->next = head;
+#ifdef HASHTABLE_COPY_KEYS
n->k = strdup(k);
+#else
+ n->k = k;
+#endif
n->v = v;
return n;
}
list_node_t* list_remove(list_node_t* head, const char* k) {
+ if(!head) return NULL;
+
list_node_t* tmp;
// head remove
while(head && strcmp(head->k, k) == 0) {
tmp = head;
head = head->next;
+#ifdef HASHTABLE_COPY_KEYS
free(tmp->k);
+#endif
free(tmp);
}
@@ -39,6 +47,9 @@ list_node_t* list_remove(list_node_t* head, const char* k) {
{
tmp = p->next;
p->next = p->next->next;
+#ifdef HASHTABLE_COPY_KEYS
+ free(tmp->k);
+#endif
free(tmp);
continue;
}
@@ -48,14 +59,14 @@ list_node_t* list_remove(list_node_t* head, const char* k) {
return head;
}
-void* list_get(list_node_t* head, const char* k) {
+list_node_t* list_get(list_node_t* head, const char* k) {
while(head) {
if(strcmp(head->k, k) == 0) {
- return head->v;
+ return head;
}
head = head->next;
}
- return (void*)0;
+ return NULL;
}
size_t list_length(list_node_t* head) {