apr-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From j..@apache.org
Subject svn commit: r1597797 - in /apr/apr/trunk: CHANGES include/apr_skiplist.h tables/apr_skiplist.c
Date Tue, 27 May 2014 14:20:29 GMT
Author: jim
Date: Tue May 27 14:20:29 2014
New Revision: 1597797

URL: http://svn.apache.org/r1597797
Log:
apr_skiplist_add()... idea from yann

Modified:
    apr/apr/trunk/CHANGES
    apr/apr/trunk/include/apr_skiplist.h
    apr/apr/trunk/tables/apr_skiplist.c

Modified: apr/apr/trunk/CHANGES
URL: http://svn.apache.org/viewvc/apr/apr/trunk/CHANGES?rev=1597797&r1=1597796&r2=1597797&view=diff
==============================================================================
--- apr/apr/trunk/CHANGES [utf-8] (original)
+++ apr/apr/trunk/CHANGES [utf-8] Tue May 27 14:20:29 2014
@@ -1,6 +1,8 @@
                                                      -*- coding: utf-8 -*-
 Changes for APR 2.0.0
 
+  *) apr_skiplist: Add apr_skiplist_add() to support multiple values.
+
   *) apr_allocator: Be less wasteful and don't return a memnode that is
      much larger than what was requested. [Stefan Fuhrmann
      <stefan fuhrmann wandisco com>]

Modified: apr/apr/trunk/include/apr_skiplist.h
URL: http://svn.apache.org/viewvc/apr/apr/trunk/include/apr_skiplist.h?rev=1597797&r1=1597796&r2=1597797&view=diff
==============================================================================
--- apr/apr/trunk/include/apr_skiplist.h (original)
+++ apr/apr/trunk/include/apr_skiplist.h Tue May 27 14:20:29 2014
@@ -180,11 +180,22 @@ APR_DECLARE(apr_skiplistnode *) apr_skip
                                           void *data, apr_skiplist_compare comp);
 
 /**
+ * Add an element into the skip list using the existing comparison function.
+ * @param sl The skip list
+ * @param data The element to insert
+ * @remark If no comparison function has been set for the skip list, the element
+ * will not be inserted and NULL will be returned. This allows for multiple
+ * values to be added to the skiplist. To replace values, use apr_skiplist_insert().
+ */
+APR_DECLARE(apr_skiplistnode *) apr_skiplist_add(apr_skiplist* sl, void *data);
+
+/**
  * Insert an element into the skip list using the existing comparison function.
  * @param sl The skip list
  * @param data The element to insert
  * @remark If no comparison function has been set for the skip list, the element
- * will not be inserted and NULL will be returned.
+ * will not be inserted and NULL will be returned. Previous values will
+ * be over-written. Use apr_skiplist_add() to allow multiple values.
  */
 APR_DECLARE(apr_skiplistnode *) apr_skiplist_insert(apr_skiplist* sl, void *data);
 

Modified: apr/apr/trunk/tables/apr_skiplist.c
URL: http://svn.apache.org/viewvc/apr/apr/trunk/tables/apr_skiplist.c?rev=1597797&r1=1597796&r2=1597797&view=diff
==============================================================================
--- apr/apr/trunk/tables/apr_skiplist.c (original)
+++ apr/apr/trunk/tables/apr_skiplist.c Tue May 27 14:20:29 2014
@@ -339,16 +339,8 @@ APR_DECLARE(void *) apr_skiplist_previou
     return (*iter) ? ((*iter)->data) : NULL;
 }
 
-APR_DECLARE(apr_skiplistnode *) apr_skiplist_insert(apr_skiplist *sl, void *data)
-{
-    if (!sl->compare) {
-        return 0;
-    }
-    return apr_skiplist_insert_compare(sl, data, sl->compare);
-}
-
-APR_DECLARE(apr_skiplistnode *) apr_skiplist_insert_compare(apr_skiplist *sl, void *data,
-                                      apr_skiplist_compare comp)
+static apr_skiplistnode *insert_compare(apr_skiplist *sl, void *data,
+                                        apr_skiplist_compare comp, int replace)
 {
     apr_skiplistnode *m, *p, *tmp, *ret = NULL, **stack;
     int nh = 1, ch, stacki;
@@ -406,11 +398,11 @@ APR_DECLARE(apr_skiplistnode *) apr_skip
         if (m->next) {
             compared = comp(data, m->next->data);
         }
-        if (compared == 0) {
+        if (compared == 0 && replace) {
             free(stack);    /* OK. was malloc'ed */
             return 0;
         }
-        if ((m->next == NULL) || (compared < 0)) {
+        if ( (compared < 0) || (replace && (m->next == NULL)) ) {
             if (ch <= nh) {
                 /* push on stack */
                 stack[stacki++] = m;
@@ -470,6 +462,34 @@ APR_DECLARE(apr_skiplistnode *) apr_skip
     return ret;
 }
 
+APR_DECLARE(apr_skiplistnode *) apr_skiplist_insert(apr_skiplist *sl, void *data)
+{
+    if (!sl->compare) {
+        return 0;
+    }
+    return insert_compare(sl, data, sl->compare, 1);
+}
+
+APR_DECLARE(apr_skiplistnode *) apr_skiplist_add_compare(apr_skiplist *sl, void *data,
+                                      apr_skiplist_compare comp)
+{
+    return insert_compare(sl, data, comp, 0);
+}
+
+APR_DECLARE(apr_skiplistnode *) apr_skiplist_add(apr_skiplist *sl, void *data)
+{
+    if (!sl->compare) {
+        return 0;
+    }
+    return insert_compare(sl, data, sl->compare, 0);
+}
+
+APR_DECLARE(apr_skiplistnode *) apr_skiplist_insert_compare(apr_skiplist *sl, void *data,
+                                      apr_skiplist_compare comp)
+{
+    return insert_compare(sl, data, comp, 1);
+}
+
 APR_DECLARE(int) apr_skiplist_remove(apr_skiplist *sl, void *data, apr_skiplist_freefunc
myfree)
 {
     if (!sl->compare) {



Mime
View raw message