aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPetr Machata <pmachata@redhat.com>2012-02-10 13:10:03 +0100
committerPetr Machata <pmachata@redhat.com>2012-04-19 00:55:01 +0200
commit345c9b5195383c7b2d2d9db308e824259323803f (patch)
tree4a245765d80e30c8d22f87864dbf2a4e99bf0386
parentfd43ef7bb48260aadd4d8335371f75015e680108 (diff)
downloadltrace-345c9b5195383c7b2d2d9db308e824259323803f.tar.gz
Dict const correctness
-rw-r--r--dict.c24
-rw-r--r--dict.h16
2 files changed, 24 insertions, 16 deletions
diff --git a/dict.c b/dict.c
index ba318cd..d7e14db 100644
--- a/dict.c
+++ b/dict.c
@@ -24,13 +24,14 @@ struct dict_entry {
struct dict {
struct dict_entry *buckets[DICTTABLESIZE];
- unsigned int (*key2hash) (void *);
- int (*key_cmp) (void *, void *);
+ unsigned int (*key2hash) (const void *);
+ int (*key_cmp) (const void *, const void *);
};
Dict *
-dict_init(unsigned int (*key2hash) (void *),
- int (*key_cmp) (void *, void *)) {
+dict_init(unsigned int (*key2hash) (const void *),
+ int (*key_cmp) (const void *, const void *))
+{
Dict *d;
int i;
@@ -103,7 +104,8 @@ dict_enter(Dict *d, void *key, void *value) {
}
void *
-dict_find_entry(Dict *d, void *key) {
+dict_find_entry(Dict *d, const void *key)
+{
unsigned int hash;
unsigned int bucketpos;
struct dict_entry *entry;
@@ -147,7 +149,8 @@ dict_apply_to_all(Dict *d,
/*****************************************************************************/
unsigned int
-dict_key2hash_string(void *key) {
+dict_key2hash_string(const void *key)
+{
const char *s = (const char *)key;
unsigned int total = 0, shift = 0;
@@ -163,19 +166,22 @@ dict_key2hash_string(void *key) {
}
int
-dict_key_cmp_string(void *key1, void *key2) {
+dict_key_cmp_string(const void *key1, const void *key2)
+{
assert(key1);
assert(key2);
return strcmp((const char *)key1, (const char *)key2);
}
unsigned int
-dict_key2hash_int(void *key) {
+dict_key2hash_int(const void *key)
+{
return (unsigned long)key;
}
int
-dict_key_cmp_int(void *key1, void *key2) {
+dict_key_cmp_int(const void *key1, const void *key2)
+{
return key1 - key2;
}
diff --git a/dict.h b/dict.h
index 27dc7bf..b2a3ffe 100644
--- a/dict.h
+++ b/dict.h
@@ -4,19 +4,21 @@
typedef struct dict Dict;
-extern Dict *dict_init(unsigned int (*key2hash) (void *),
- int (*key_cmp) (void *, void *));
+extern Dict *dict_init(unsigned int (*key2hash) (const void *),
+ int (*key_cmp) (const void *, const void *));
extern void dict_clear(Dict *d);
extern int dict_enter(Dict *d, void *key, void *value);
-extern void *dict_find_entry(Dict *d, void *key);
+extern void *dict_find_entry(Dict *d, const void *key);
extern void dict_apply_to_all(Dict *d,
void (*func) (void *key, void *value, void *data),
void *data);
-extern unsigned int dict_key2hash_string(void *key);
-extern int dict_key_cmp_string(void *key1, void *key2);
-extern unsigned int dict_key2hash_int(void *key);
-extern int dict_key_cmp_int(void *key1, void *key2);
+extern unsigned int dict_key2hash_string(const void *key);
+extern int dict_key_cmp_string(const void *key1, const void *key2);
+
+extern unsigned int dict_key2hash_int(const void *key);
+extern int dict_key_cmp_int(const void *key1, const void *key2);
+
extern Dict * dict_clone(Dict *old, void * (*key_clone)(void*), void * (*value_clone)(void*));
extern Dict * dict_clone2(Dict * old,
void * (* key_clone)(void * key, void * data),