Author: jmb
Date: Sun Jan 25 16:47:11 2009
New Revision: 6272

URL: http://source.netsurf-browser.org?rev=6272&view=rev
Log:
Add ability to delete items from the selector hash (we use lazy deletion, as 
it's simpler)

Modified:
    trunk/libcss/src/select/hash.c
    trunk/libcss/src/select/hash.h

Modified: trunk/libcss/src/select/hash.c
URL: 
http://source.netsurf-browser.org/trunk/libcss/src/select/hash.c?rev=6272&r1=6271&r2=6272&view=diff
==============================================================================
--- trunk/libcss/src/select/hash.c (original)
+++ trunk/libcss/src/select/hash.c Sun Jan 25 16:47:11 2009
@@ -21,6 +21,9 @@
        css_alloc alloc;
        void *pw;
 };
+
+/* Dummy selector, used for lazy deletion */
+static css_selector empty_slot;
 
 static inline uint32_t _hash(const css_selector *sel);
 static inline uint32_t _hash_name(const parserutils_hash_entry *name);
@@ -126,6 +129,44 @@
 }
 
 /**
+ * Remove an item from a hash
+ *
+ * \param hash      The hash to remove from
+ * \param selector  Pointer to selector
+ * \return CSS_OK on success, appropriate error otherwise
+ */
+css_error css_selector_hash_remove(css_selector_hash *hash,
+               const css_selector *selector)
+{
+       uint32_t index, mask;
+       const css_selector **entries;
+       const css_selector *entry;
+
+       if (hash == NULL || selector == NULL)
+               return CSS_BADPARM;
+
+       entries = hash->slots;
+
+       /* Find index */
+       mask = hash->n_slots - 1;
+       index = _hash(selector) & mask;
+
+       /* Use linear probing to resolve collisions */
+       while ((entry = entries[index]) != NULL) {
+               /* If we've found the right entry, invalidate it */
+               if (selector == entry) {
+                       entries[index] = &empty_slot;
+                       return CSS_OK;
+               }
+
+               index = (index + 1) & mask;
+       }
+
+       return CSS_OK;
+}
+
+
+/**
  * Find the first selector that matches name
  *
  * \param hash     Hash to search
@@ -155,7 +196,7 @@
        /* Use linear probing to resolve collisions */
        while ((entry = entries[index]) != NULL) {
                /* Names match, so we're done here */
-               if (entry->data.name == name) {
+               if (entry != &empty_slot && entry->data.name == name) {
                        break;
                }
 
@@ -196,7 +237,8 @@
 
        /* Use linear probing to resolve collisions */
        while ((entry = entries[index]) != NULL) {
-               if (entry->data.name == (*current)->data.name) {
+               if (entry != &empty_slot &&
+                               entry->data.name == (*current)->data.name) {
                        break;
                }
 
@@ -261,7 +303,10 @@
        for (uint32_t i = 0; i < hash->n_slots; i++) {
                const css_selector *e = hash->slots[i];
 
-               if (e == NULL)
+               /* Ignore unused slots, 
+                * and slots containing lazily-deleted items
+                */
+               if (e == NULL || e == &empty_slot)
                        continue;
 
                /* Find new index */

Modified: trunk/libcss/src/select/hash.h
URL: 
http://source.netsurf-browser.org/trunk/libcss/src/select/hash.h?rev=6272&r1=6271&r2=6272&view=diff
==============================================================================
--- trunk/libcss/src/select/hash.h (original)
+++ trunk/libcss/src/select/hash.h Sun Jan 25 16:47:11 2009
@@ -24,6 +24,8 @@
 
 css_error css_selector_hash_insert(css_selector_hash *hash,
                const struct css_selector *selector);
+css_error css_selector_hash_remove(css_selector_hash *hash,
+               const struct css_selector *selector);
 
 css_error css_selector_hash_find(css_selector_hash *hash,
                const parserutils_hash_entry *name,


_______________________________________________
netsurf-commits mailing list
[email protected]
http://vlists.pepperfish.net/cgi-bin/mailman/listinfo/netsurf-commits-netsurf-browser.org

Reply via email to