[gnome-builder] fuzzy: add fuzzy_contains()
- From: Christian Hergert <chergert src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-builder] fuzzy: add fuzzy_contains()
- Date: Thu, 15 Oct 2015 18:08:58 +0000 (UTC)
commit 089797c66764ecc31250ea4ab909f31080dade04
Author: Christian Hergert <chergert redhat com>
Date: Thu Oct 15 10:50:41 2015 -0700
fuzzy: add fuzzy_contains()
A helper to detect if a key already exists within the fuzzy index. This
cannot be used from bulk insertion as the lookup tables will not have
been built.
contrib/search/fuzzy.c | 20 ++++++++++++++++++--
contrib/search/fuzzy.h | 2 ++
2 files changed, 20 insertions(+), 2 deletions(-)
---
diff --git a/contrib/search/fuzzy.c b/contrib/search/fuzzy.c
index 95b0b52..302b251 100644
--- a/contrib/search/fuzzy.c
+++ b/contrib/search/fuzzy.c
@@ -232,7 +232,7 @@ fuzzy_insert (Fuzzy *fuzzy,
gsize offset;
guint id;
- if (G_UNLIKELY (!*key || (fuzzy->id_to_text_offset->len == G_MAXUINT)))
+ if (G_UNLIKELY (!key || !*key || (fuzzy->id_to_text_offset->len == G_MAXUINT)))
return;
if (!fuzzy->case_sensitive)
@@ -295,7 +295,7 @@ fuzzy_unref (Fuzzy *fuzzy)
g_return_if_fail (fuzzy);
g_return_if_fail (fuzzy->ref_count > 0);
- if (g_atomic_int_dec_and_test (&fuzzy->ref_count))
+ if (G_UNLIKELY (g_atomic_int_dec_and_test (&fuzzy->ref_count)))
{
g_byte_array_unref (fuzzy->heap);
fuzzy->heap = NULL;
@@ -498,3 +498,19 @@ cleanup:
return matches;
}
+
+gboolean
+fuzzy_contains (Fuzzy *fuzzy,
+ const gchar *key)
+{
+ GArray *ar;
+ gboolean ret;
+
+ g_return_val_if_fail (fuzzy != NULL, FALSE);
+
+ ar = fuzzy_match (fuzzy, key, 1);
+ ret = (ar != NULL) && (ar->len > 0);
+ g_clear_pointer (&ar, g_array_unref);
+
+ return ret;
+}
diff --git a/contrib/search/fuzzy.h b/contrib/search/fuzzy.h
index e3a1598..8b45691 100644
--- a/contrib/search/fuzzy.h
+++ b/contrib/search/fuzzy.h
@@ -40,6 +40,8 @@ void fuzzy_set_free_func (Fuzzy *fuzzy,
GDestroyNotify free_func);
void fuzzy_begin_bulk_insert (Fuzzy *fuzzy);
void fuzzy_end_bulk_insert (Fuzzy *fuzzy);
+gboolean fuzzy_contains (Fuzzy *fuzzy,
+ const gchar *key);
void fuzzy_insert (Fuzzy *fuzzy,
const gchar *key,
gpointer value);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]