Precis:
This is Bo Yang's first attempt at a patch to add a feature to
libwapcaplet to allow the user of an lwc_string to retrieve a
hash value of the string without necessarily having to compute it
themselves. This allows lwc_string objects to be more usefully
used as keys in tables or put into sets etc.
Added files
Changed files
include/libwapcaplet/libwapcaplet.h | 15 +++++++++++++++
src/libwapcaplet.c | 7 +++++++
2 files changed, 22 insertions(+)
Index: include/libwapcaplet/libwapcaplet.h
===================================================================
--- include/libwapcaplet/libwapcaplet.h (revision 6881)
+++ include/libwapcaplet/libwapcaplet.h (working copy)
@@ -126,5 +126,20 @@ extern const char *lwc_string_data(lwc_s
*/
extern size_t lwc_string_length(lwc_string *str);
+/**
+ * Retrieve the hask value of the string.
+ *
+ * @note The API should be used as a convenient way of get the underlaid
+ * string's hash value. And the hash value should never be used to
+ * identified the string, some code as:
+ *
+ * if (hashvalue == 0xb1ab1a00) {
+ * assume string == "div"
+ * }
+ *
+ * should never appear. The hash value is suitable for a hash table
+ * key.
+ */
+extern uint32_t lwc_string_hash_value(lwc_string *str);
#endif /* libwapcaplet_h_ */
Index: src/libwapcaplet.c
===================================================================
--- src/libwapcaplet.c (revision 6881)
+++ src/libwapcaplet.c (working copy)
@@ -342,3 +342,10 @@ lwc_string_length(lwc_string *str)
return str->len;
}
+
+uint32_t lwc_string_hash_value(lwc_string *str)
+{
+ assert(str);
+
+ return str->hash;
+}
Conflicted files
Removed files