[Xenomai-git] Philippe Gerum : copperplate/hash: introduce generic key type

2013-06-12 Thread git repository hosting
Module: xenomai-forge
Branch: master
Commit: 7abd2865e72107906fae89525258c6ea7bea2ebd
URL:
http://git.xenomai.org/?p=xenomai-forge.git;a=commit;h=7abd2865e72107906fae89525258c6ea7bea2ebd

Author: Philippe Gerum r...@xenomai.org
Date:   Thu Jun  6 11:38:45 2013 +0200

copperplate/hash: introduce generic key type

We don't want hash keys to be restricted to character strings
anymore.

Client code may now use whatever key type fits, mentioning the actual
key length in all relevant calls. In addition, the node comparison
routine has to be specified in the [pv]hash_init() call.

---

 include/copperplate/hash.h|   83 +--
 lib/copperplate/cluster.c |   21 
 lib/copperplate/hash.c|  100 +
 lib/copperplate/heapobj-pshared.c |2 +-
 lib/copperplate/registry.c|   25 +-
 5 files changed, 148 insertions(+), 83 deletions(-)

diff --git a/include/copperplate/hash.h b/include/copperplate/hash.h
index d43cfb4..b29381b 100644
--- a/include/copperplate/hash.h
+++ b/include/copperplate/hash.h
@@ -25,7 +25,8 @@
 #define HASHSLOTS  (18)
 
 struct hashobj {
-   const char *key;
+   const void *key;
+   size_t len;
struct holder link;
 };
 
@@ -35,13 +36,16 @@ struct hash_bucket {
 
 struct hash_table {
struct hash_bucket table[HASHSLOTS];
+   int (*compare)(const struct hashobj *l,
+  const struct hashobj *r);
pthread_mutex_t lock;
 };
 
 #ifdef CONFIG_XENO_PSHARED
 /* Private version - not shareable between processes. */
 struct pvhashobj {
-   const char *key;
+   const void *key;
+   size_t len;
struct pvholder link;
 };
 
@@ -51,6 +55,8 @@ struct pvhash_bucket {
 
 struct pvhash_table {
struct pvhash_bucket table[HASHSLOTS];
+   int (*compare)(const struct pvhashobj *l,
+  const struct pvhashobj *r);
pthread_mutex_t lock;
 };
 #else /* !CONFIG_XENO_PSHARED */
@@ -64,93 +70,115 @@ extern C {
 #endif
 
 unsigned int __hash_key(const void *key,
-   int length, unsigned int c);
+   size_t length, unsigned int c);
 
-void __hash_init(void *heap, struct hash_table *t);
+void __hash_init(void *heap, struct hash_table *t,
+int (*compare)(const struct hashobj *l,
+   const struct hashobj *r));
 
 int __hash_enter(struct hash_table *t,
-const char *key, struct hashobj *newobj,
-int nodup);
+const void *key, size_t len,
+struct hashobj *newobj, int nodup);
 
-static inline void hash_init(struct hash_table *t)
+static inline void hash_init(struct hash_table *t,
+int (*compare)(const struct hashobj *l,
+   const struct hashobj *r))
 {
-   __hash_init(__main_heap, t);
+   __hash_init(__main_heap, t, compare);
 }
 
 void hash_destroy(struct hash_table *t);
 
 static inline int hash_enter(struct hash_table *t,
-const char *key, struct hashobj *newobj)
+const void *key, size_t len,
+struct hashobj *newobj)
 {
-   return __hash_enter(t, key, newobj, 1);
+   return __hash_enter(t, key, len, newobj, 1);
 }
 
 static inline int hash_enter_dup(struct hash_table *t,
-const char *key, struct hashobj *newobj)
+const void *key, size_t len,
+struct hashobj *newobj)
 {
-   return __hash_enter(t, key, newobj, 0);
+   return __hash_enter(t, key, len, newobj, 0);
 }
 
 int hash_remove(struct hash_table *t, struct hashobj *delobj);
 
-struct hashobj *hash_search(struct hash_table *t, const char *key);
+struct hashobj *hash_search(struct hash_table *t,
+   const void *key, size_t len);
 
 int hash_walk(struct hash_table *t,
int (*walk)(struct hash_table *t, struct hashobj *obj));
 
+int hash_compare_strings(const struct hashobj *l,
+const struct hashobj *r);
+
 #ifdef CONFIG_XENO_PSHARED
 
 int __hash_enter_probe(struct hash_table *t,
-  const char *key, struct hashobj *newobj,
+  const void *key, size_t len,
+  struct hashobj *newobj,
   int (*probefn)(struct hashobj *oldobj),
   int nodup);
 
 int __pvhash_enter(struct pvhash_table *t,
-  const char *key, struct pvhashobj *newobj,
-  int nodup);
+  const void *key, size_t len,
+  struct pvhashobj *newobj, int nodup);
 
 static inline
 int hash_enter_probe(struct hash_table *t,
-const char *key, struct hashobj *newobj,
+const void *key, size_t len,
+struct hashobj 

[Xenomai-git] Philippe Gerum : copperplate/hash: introduce generic key type

2013-06-12 Thread git repository hosting
Module: xenomai-forge
Branch: next
Commit: 7abd2865e72107906fae89525258c6ea7bea2ebd
URL:
http://git.xenomai.org/?p=xenomai-forge.git;a=commit;h=7abd2865e72107906fae89525258c6ea7bea2ebd

Author: Philippe Gerum r...@xenomai.org
Date:   Thu Jun  6 11:38:45 2013 +0200

copperplate/hash: introduce generic key type

We don't want hash keys to be restricted to character strings
anymore.

Client code may now use whatever key type fits, mentioning the actual
key length in all relevant calls. In addition, the node comparison
routine has to be specified in the [pv]hash_init() call.

---

 include/copperplate/hash.h|   83 +--
 lib/copperplate/cluster.c |   21 
 lib/copperplate/hash.c|  100 +
 lib/copperplate/heapobj-pshared.c |2 +-
 lib/copperplate/registry.c|   25 +-
 5 files changed, 148 insertions(+), 83 deletions(-)

diff --git a/include/copperplate/hash.h b/include/copperplate/hash.h
index d43cfb4..b29381b 100644
--- a/include/copperplate/hash.h
+++ b/include/copperplate/hash.h
@@ -25,7 +25,8 @@
 #define HASHSLOTS  (18)
 
 struct hashobj {
-   const char *key;
+   const void *key;
+   size_t len;
struct holder link;
 };
 
@@ -35,13 +36,16 @@ struct hash_bucket {
 
 struct hash_table {
struct hash_bucket table[HASHSLOTS];
+   int (*compare)(const struct hashobj *l,
+  const struct hashobj *r);
pthread_mutex_t lock;
 };
 
 #ifdef CONFIG_XENO_PSHARED
 /* Private version - not shareable between processes. */
 struct pvhashobj {
-   const char *key;
+   const void *key;
+   size_t len;
struct pvholder link;
 };
 
@@ -51,6 +55,8 @@ struct pvhash_bucket {
 
 struct pvhash_table {
struct pvhash_bucket table[HASHSLOTS];
+   int (*compare)(const struct pvhashobj *l,
+  const struct pvhashobj *r);
pthread_mutex_t lock;
 };
 #else /* !CONFIG_XENO_PSHARED */
@@ -64,93 +70,115 @@ extern C {
 #endif
 
 unsigned int __hash_key(const void *key,
-   int length, unsigned int c);
+   size_t length, unsigned int c);
 
-void __hash_init(void *heap, struct hash_table *t);
+void __hash_init(void *heap, struct hash_table *t,
+int (*compare)(const struct hashobj *l,
+   const struct hashobj *r));
 
 int __hash_enter(struct hash_table *t,
-const char *key, struct hashobj *newobj,
-int nodup);
+const void *key, size_t len,
+struct hashobj *newobj, int nodup);
 
-static inline void hash_init(struct hash_table *t)
+static inline void hash_init(struct hash_table *t,
+int (*compare)(const struct hashobj *l,
+   const struct hashobj *r))
 {
-   __hash_init(__main_heap, t);
+   __hash_init(__main_heap, t, compare);
 }
 
 void hash_destroy(struct hash_table *t);
 
 static inline int hash_enter(struct hash_table *t,
-const char *key, struct hashobj *newobj)
+const void *key, size_t len,
+struct hashobj *newobj)
 {
-   return __hash_enter(t, key, newobj, 1);
+   return __hash_enter(t, key, len, newobj, 1);
 }
 
 static inline int hash_enter_dup(struct hash_table *t,
-const char *key, struct hashobj *newobj)
+const void *key, size_t len,
+struct hashobj *newobj)
 {
-   return __hash_enter(t, key, newobj, 0);
+   return __hash_enter(t, key, len, newobj, 0);
 }
 
 int hash_remove(struct hash_table *t, struct hashobj *delobj);
 
-struct hashobj *hash_search(struct hash_table *t, const char *key);
+struct hashobj *hash_search(struct hash_table *t,
+   const void *key, size_t len);
 
 int hash_walk(struct hash_table *t,
int (*walk)(struct hash_table *t, struct hashobj *obj));
 
+int hash_compare_strings(const struct hashobj *l,
+const struct hashobj *r);
+
 #ifdef CONFIG_XENO_PSHARED
 
 int __hash_enter_probe(struct hash_table *t,
-  const char *key, struct hashobj *newobj,
+  const void *key, size_t len,
+  struct hashobj *newobj,
   int (*probefn)(struct hashobj *oldobj),
   int nodup);
 
 int __pvhash_enter(struct pvhash_table *t,
-  const char *key, struct pvhashobj *newobj,
-  int nodup);
+  const void *key, size_t len,
+  struct pvhashobj *newobj, int nodup);
 
 static inline
 int hash_enter_probe(struct hash_table *t,
-const char *key, struct hashobj *newobj,
+const void *key, size_t len,
+struct hashobj *newobj,