[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[tyndur-devel] [PATCH 2/2] libc: key_mask fuer Baeume



+ libc: Nicht alle 64 Bit des Schluessels muessen als Schluessel benutzt
  werden, sondern koennen z.B. Flags enthalten. Das neue Feld key_mask
  filtert dann raus, was nicht zum Schluessel gehoert
---
 src/include/collections.h  |    1 +
 src/lib/collections/tree.c |    6 +++++-
 2 files changed, 6 insertions(+), 1 deletions(-)

diff --git a/src/include/collections.h b/src/include/collections.h
index 2593e3a..0ecb321 100644
--- a/src/include/collections.h
+++ b/src/include/collections.h
@@ -81,6 +81,7 @@ typedef struct {
     struct tree_item*   root;
     size_t              tree_item_offset;
     size_t              sort_key_offset;
+    uint64_t            key_mask;
 } tree_t;
 
 /**
diff --git a/src/lib/collections/tree.c b/src/lib/collections/tree.c
index 01c0a71..87dbcea 100644
--- a/src/lib/collections/tree.c
+++ b/src/lib/collections/tree.c
@@ -53,7 +53,10 @@ static inline struct tree_item* to_tree_item(tree_t* tree, void* node) {
  * Gibt den Schluessel eines Objekts zurueck
  */
 static inline uint64_t get_key(tree_t* tree, struct tree_item* item) {
-    return *(uint64_t*)((char*) to_node(tree, item) + tree->sort_key_offset);
+    uint64_t res;
+
+    res = *(uint64_t*)((char*) to_node(tree, item) + tree->sort_key_offset);
+    return res & tree->key_mask;
 }
 
 /**
@@ -66,6 +69,7 @@ void tree_do_init(tree_t* tree,
     memset(tree, 0, sizeof(*tree));
     tree->tree_item_offset = tree_item_offset;
     tree->sort_key_offset = sort_key_offset;
+    tree->key_mask = (uint64_t) -1;
 }
 
 /**
-- 
1.6.0.2