]> mj.ucw.cz Git - leo.git/commitdiff
Dictionaries support encoding without creation of new entries
authorMartin Mares <mj@ucw.cz>
Sun, 7 Jun 2015 15:34:51 +0000 (17:34 +0200)
committerMartin Mares <mj@ucw.cz>
Sun, 7 Jun 2015 15:34:51 +0000 (17:34 +0200)
dict.c
dict.h
style.h

diff --git a/dict.c b/dict.c
index a3679e713c1425f1a890cc0a41664744e11a2086..4542322a2ac72d47ec3cf6cf455a644a27d0fe62 100644 (file)
--- a/dict.c
+++ b/dict.c
@@ -1,7 +1,7 @@
 /*
  *     Hic Est Leo -- Universal Dictionaries
  *
- *     (c) 2014 Martin Mares <mj@ucw.cz>
+ *     (c) 2014--2015 Martin Mares <mj@ucw.cz>
  */
 
 #include <ucw/lib.h>
@@ -18,6 +18,7 @@ struct kv_map {
 #define HASH_NODE struct kv_map
 #define HASH_PREFIX(x) kv_map_##x
 #define HASH_KEY_STRING name
+#define HASH_WANT_FIND
 #define HASH_WANT_LOOKUP
 #define HASH_AUTO_POOL 4096
 #define HASH_ZERO_FILL
@@ -61,3 +62,9 @@ u32 dict_encode(struct dict *d, const char *key)
   *GARY_PUSH(d->names) = k->name;
   return k->id;
 }
+
+u32 dict_encode_if_exists(struct dict *d, const char *key)
+{
+  struct kv_map *k = kv_map_find(d->hash, (char *) key);
+  return k ? k->id : 0;
+}
diff --git a/dict.h b/dict.h
index f214bd7bf8be952c457841e3a9f6306e48278bd5..49d681ee21d6cafd6b3761711ac83087c27cadbd 100644 (file)
--- a/dict.h
+++ b/dict.h
@@ -1,7 +1,7 @@
 /*
  *     Hic Est Leo -- Universal Dictionaries
  *
- *     (c) 2014 Martin Mares <mj@ucw.cz>
+ *     (c) 2014--2015 Martin Mares <mj@ucw.cz>
  */
 
 #ifndef _LEO_DICT_H
@@ -24,6 +24,7 @@ static inline const char *dict_decode(struct dict *d, u32 id)
 }
 
 u32 dict_encode(struct dict *d, const char *key);
+u32 dict_encode_if_exists(struct dict *d, const char *key);
 
 static inline u32 dict_size(struct dict *d)
 {
diff --git a/style.h b/style.h
index 83508cfce5eaa53e39558f30a9e1e3af01ee6cd4..fb1ff8d1a9471aa9f64b981d7277a4a7c8ecf12b 100644 (file)
--- a/style.h
+++ b/style.h
@@ -95,6 +95,11 @@ static inline layer_t style_layer_encode(const char *key)
   return dict_encode(&style_layer_dict, key);
 }
 
+static inline layer_t style_layer_encode_if_exists(const char *key)
+{
+  return dict_encode_if_exists(&style_layer_dict, key);
+}
+
 static inline const char *style_layer_decode(layer_t id)
 {
   return dict_decode(&style_layer_dict, id);