projects
/
jansson.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Truncate error source from start, not end, if it's too long to fit
[jansson.git]
/
src
/
hashtable.c
diff --git
a/src/hashtable.c
b/src/hashtable.c
index
dcba68a
..
de25c21
100644
(file)
--- a/
src/hashtable.c
+++ b/
src/hashtable.c
@@
-1,31
+1,28
@@
/*
/*
- * Copyright (c) 2009
, 2010
Petri Lehtinen <petri@digip.org>
+ * Copyright (c) 2009
-2011
Petri Lehtinen <petri@digip.org>
*
* This library is free software; you can redistribute it and/or modify
* it under the terms of the MIT license. See LICENSE for details.
*/
*
* This library is free software; you can redistribute it and/or modify
* it under the terms of the MIT license. See LICENSE for details.
*/
-#include <config.h>
-
#include <stdlib.h>
#include <stdlib.h>
+#include <jansson_config.h> /* for JSON_INLINE */
+#include "jansson_private.h" /* for container_of() */
#include "hashtable.h"
typedef struct hashtable_list list_t;
typedef struct hashtable_pair pair_t;
typedef struct hashtable_bucket bucket_t;
#include "hashtable.h"
typedef struct hashtable_list list_t;
typedef struct hashtable_pair pair_t;
typedef struct hashtable_bucket bucket_t;
-#define container_of(ptr_, type_, member_) \
- ((type_ *)((char *)ptr_ - (size_t)&((type_ *)0)->member_))
-
#define list_to_pair(list_) container_of(list_, pair_t, list)
#define list_to_pair(list_) container_of(list_, pair_t, list)
-static
inline
void list_init(list_t *list)
+static
JSON_INLINE
void list_init(list_t *list)
{
list->next = list;
list->prev = list;
}
{
list->next = list;
list->prev = list;
}
-static
inline
void list_insert(list_t *list, list_t *node)
+static
JSON_INLINE
void list_insert(list_t *list, list_t *node)
{
node->next = list;
node->prev = list->prev;
{
node->next = list;
node->prev = list->prev;
@@
-33,13
+30,13
@@
static inline void list_insert(list_t *list, list_t *node)
list->prev = node;
}
list->prev = node;
}
-static
inline
void list_remove(list_t *list)
+static
JSON_INLINE
void list_remove(list_t *list)
{
list->prev->next = list->next;
list->next->prev = list->prev;
}
{
list->prev->next = list->next;
list->next->prev = list->prev;
}
-static
inline
int bucket_is_empty(hashtable_t *hashtable, bucket_t *bucket)
+static
JSON_INLINE
int bucket_is_empty(hashtable_t *hashtable, bucket_t *bucket)
{
return bucket->first == &hashtable->list && bucket->first == bucket->last;
}
{
return bucket->first == &hashtable->list && bucket->first == bucket->last;
}
@@
-67,7
+64,7
@@
static size_t primes[] = {
};
static const size_t num_primes = sizeof(primes) / sizeof(size_t);
};
static const size_t num_primes = sizeof(primes) / sizeof(size_t);
-static
inline
size_t num_buckets(hashtable_t *hashtable)
+static
JSON_INLINE
size_t num_buckets(hashtable_t *hashtable)
{
return primes[hashtable->num_buckets];
}
{
return primes[hashtable->num_buckets];
}
@@
-148,7
+145,7
@@
static void hashtable_do_clear(hashtable_t *hashtable)
hashtable->free_key(pair->key);
if(hashtable->free_value)
hashtable->free_value(pair->value);
hashtable->free_key(pair->key);
if(hashtable->free_value)
hashtable->free_value(pair->value);
- free(pair);
+
jsonp_
free(pair);
}
}
}
}
@@
-158,12
+155,12
@@
static int hashtable_do_rehash(hashtable_t *hashtable)
pair_t *pair;
size_t i, index, new_size;
pair_t *pair;
size_t i, index, new_size;
- free(hashtable->buckets);
+
jsonp_
free(hashtable->buckets);
hashtable->num_buckets++;
new_size = num_buckets(hashtable);
hashtable->num_buckets++;
new_size = num_buckets(hashtable);
- hashtable->buckets = malloc(new_size * sizeof(bucket_t));
+ hashtable->buckets =
jsonp_
malloc(new_size * sizeof(bucket_t));
if(!hashtable->buckets)
return -1;
if(!hashtable->buckets)
return -1;
@@
-190,13
+187,13
@@
static int hashtable_do_rehash(hashtable_t *hashtable)
hashtable_t *hashtable_create(key_hash_fn hash_key, key_cmp_fn cmp_keys,
free_fn free_key, free_fn free_value)
{
hashtable_t *hashtable_create(key_hash_fn hash_key, key_cmp_fn cmp_keys,
free_fn free_key, free_fn free_value)
{
- hashtable_t *hashtable = malloc(sizeof(hashtable_t));
+ hashtable_t *hashtable =
jsonp_
malloc(sizeof(hashtable_t));
if(!hashtable)
return NULL;
if(hashtable_init(hashtable, hash_key, cmp_keys, free_key, free_value))
{
if(!hashtable)
return NULL;
if(hashtable_init(hashtable, hash_key, cmp_keys, free_key, free_value))
{
- free(hashtable);
+
jsonp_
free(hashtable);
return NULL;
}
return NULL;
}
@@
-206,7
+203,7
@@
hashtable_t *hashtable_create(key_hash_fn hash_key, key_cmp_fn cmp_keys,
void hashtable_destroy(hashtable_t *hashtable)
{
hashtable_close(hashtable);
void hashtable_destroy(hashtable_t *hashtable)
{
hashtable_close(hashtable);
- free(hashtable);
+
jsonp_
free(hashtable);
}
int hashtable_init(hashtable_t *hashtable,
}
int hashtable_init(hashtable_t *hashtable,
@@
-217,7
+214,7
@@
int hashtable_init(hashtable_t *hashtable,
hashtable->size = 0;
hashtable->num_buckets = 0; /* index to primes[] */
hashtable->size = 0;
hashtable->num_buckets = 0; /* index to primes[] */
- hashtable->buckets = malloc(num_buckets(hashtable) * sizeof(bucket_t));
+ hashtable->buckets =
jsonp_
malloc(num_buckets(hashtable) * sizeof(bucket_t));
if(!hashtable->buckets)
return -1;
if(!hashtable->buckets)
return -1;
@@
-240,7
+237,7
@@
int hashtable_init(hashtable_t *hashtable,
void hashtable_close(hashtable_t *hashtable)
{
hashtable_do_clear(hashtable);
void hashtable_close(hashtable_t *hashtable)
{
hashtable_do_clear(hashtable);
- free(hashtable->buckets);
+
jsonp_
free(hashtable->buckets);
}
int hashtable_set(hashtable_t *hashtable, void *key, void *value)
}
int hashtable_set(hashtable_t *hashtable, void *key, void *value)
@@
-269,7
+266,7
@@
int hashtable_set(hashtable_t *hashtable, void *key, void *value)
}
else
{
}
else
{
- pair = malloc(sizeof(pair_t));
+ pair =
jsonp_
malloc(sizeof(pair_t));
if(!pair)
return -1;
if(!pair)
return -1;