summaryrefslogtreecommitdiffstats
path: root/lib/vector.c
diff options
context:
space:
mode:
authorChris Hall (GMCH) <chris.hall@highwayman.com>2009-12-06 23:08:06 +0000
committerChris Hall (GMCH) <chris.hall@highwayman.com>2009-12-06 23:08:06 +0000
commit391f49fa132d167378dffbad44ac87d71dfa6b80 (patch)
tree7b2dd497e24b95d6bb19732dd11808745177e8fe /lib/vector.c
parent1a720bbef1c1bbe6bf29abe34b736e077e8dd864 (diff)
downloadquagga-391f49fa132d167378dffbad44ac87d71dfa6b80.tar.bz2
quagga-391f49fa132d167378dffbad44ac87d71dfa6b80.tar.xz
Updates after code review: lib/heap.c & .h lib/vector.c & .h
Added vector_unset_item() & recast vector_unset(). Added heap_pop_push_item() and made a number of simple operations Inline functions.
Diffstat (limited to 'lib/vector.c')
-rw-r--r--lib/vector.c62
1 files changed, 32 insertions, 30 deletions
diff --git a/lib/vector.c b/lib/vector.c
index 8268c830..ad2af289 100644
--- a/lib/vector.c
+++ b/lib/vector.c
@@ -234,6 +234,38 @@ vector_ream(vector v, int free_structure)
} ;
/*==============================================================================
+ * Unset item.
+ */
+
+/* Unset item at given index (ie set it NULL).
+ *
+ * Return the old value of the item.
+ *
+ * If the item at the current (logical) end of the vector is NULL, move the
+ * end backwards until finds a non-NULL item, or the vetor becomes empty.
+ */
+extern p_vector_item
+vector_unset_item(vector v, vector_index i)
+{
+ p_vector_item was ;
+ if (i < v->end)
+ {
+ was = v->p_items[i] ;
+ v->p_items[i] = NULL ;
+ }
+ else
+ was = NULL ;
+
+ /* Now move end back past any NULLs */
+ i = v->end ;
+ while ((i > 0) && (v->p_items[i-1] == NULL))
+ --i ;
+ v->end = i ;
+
+ return was ;
+} ;
+
+/*==============================================================================
* Inserting and deleting items.
*/
@@ -822,36 +854,6 @@ vector_lookup_ensure (vector v, vector_index i)
return v->p_items[i];
}
-/* Unset value at specified index slot. */
-void
-vector_unset (vector v, vector_index i)
-{
- vector_index j ;
- if (i >= v->end)
- return; /* Everything beyond or at end is implicitly NULL */
-
- v->p_items[i] = NULL;
-
- /* See if everything ahead of 'i' is also NULL. */
- j = i ;
- while (++j < v->end)
- if (v->p_items[j] != NULL)
- return ; /* Finished if anything ahead 'i' is not NULL */
-
- /* Everything from 'i' onwards is NULL.
- * Step backwards across any NULLs and then set the new end.
- */
-#if 0
- v->end--;
- while (i && v->p_items[--i] == NULL && v->end--)
- ; /* Is this ugly ? */
-#endif
- while ((i != 0) && (v->p_items[i - 1] == NULL))
- --i ;
-
- v->end = i ;
-}
-
/* Count the number of not empty slots. */
vector_index
vector_count (vector v)