[510] in BarnOwl Developers

home help back first fref pref prev next nref lref last post

[D-O-H] r630 - in trunk: . owl

daemon@ATHENA.MIT.EDU (nelhage@MIT.EDU)
Thu Oct 29 18:06:56 2009

Resent-From: nelhage@mit.edu
Resent-To: barnowl-dev-mtg@charon.mit.edu
To: dirty-owl-hackers@mit.edu
From: nelhage@MIT.EDU
Reply-to: dirty-owl-hackers@MIT.EDU
Date: Wed, 28 Feb 2007 21:07:16 -0500 (EST)

Author: nelhage
Date: 2007-02-28 21:07:15 -0500 (Wed, 28 Feb 2007)
New Revision: 630

Modified:
   trunk/
   trunk/owl/list.c
Log:
 r19145@phanatique:  nelhage | 2007-02-27 23:37:40 -0500
 Refactoring list, to include a generic insert method
 



Property changes on: trunk
___________________________________________________________________
Name: svk:merge
   - bb873fd7-8e23-0410-944a-99ec44c633eb:/branches/owl/filter-rewrite:15925
bb873fd7-8e23-0410-944a-99ec44c633eb:/local/d-o-h/trunk:19100
   + bb873fd7-8e23-0410-944a-99ec44c633eb:/branches/owl/filter-rewrite:15925
bb873fd7-8e23-0410-944a-99ec44c633eb:/local/d-o-h/trunk:19145

Modified: trunk/owl/list.c
===================================================================
--- trunk/owl/list.c	2007-02-25 01:58:27 UTC (rev 629)
+++ trunk/owl/list.c	2007-03-01 02:07:15 UTC (rev 630)
@@ -21,48 +21,51 @@
   return(l->size);
 }
 
-void *owl_list_get_element(owl_list *l, int n)
-{
-  if (n>l->size-1) return(NULL);
-  return(l->list[n]);
-}
 
-int owl_list_append_element(owl_list *l, void *element)
+void owl_list_grow(owl_list *l, int n) /*noproto*/
 {
   void *ptr;
-  
-  if ((l->size+1) > (l->avail/GROWAT)) {
+
+  if ((l->size+n) > (l->avail/GROWAT)) {
     ptr=owl_realloc(l->list, l->avail*GROWBY*sizeof(void *));
-    if (ptr==NULL) return(-1);
+    if (ptr==NULL) abort();
     l->list=ptr;
     l->avail=l->avail*GROWBY;
   }
 
-  l->list[l->size]=element;
-  l->size++;
-  return(0);
 }
 
-int owl_list_prepend_element(owl_list *l, void *element)
+void *owl_list_get_element(owl_list *l, int n)
 {
-  void *ptr;
+  if (n>l->size-1) return(NULL);
+  return(l->list[n]);
+}
+
+int owl_list_insert_element(owl_list *l, int at, void *element)
+{
   int i;
- 
-  if ((l->size+1) > (l->avail/GROWAT)) {
-    ptr=owl_realloc(l->list, l->avail*GROWBY*sizeof(void *));
-    if (ptr==NULL) return(-1);
-    l->list=ptr;
-    l->avail=l->avail*GROWBY;
-  }
+  if(at < 0 || at > l->size) return -1;
+  owl_list_grow(l, 1);
 
-  for (i=l->size; i>0; i--) {
+  for (i=l->size; i>at; i--) {
     l->list[i]=l->list[i-1];
   }
-  l->list[0]=element;
+
+  l->list[at] = element;
   l->size++;
   return(0);
 }
 
+int owl_list_append_element(owl_list *l, void *element)
+{
+  return owl_list_insert_element(l, l->size, element);
+}
+
+int owl_list_prepend_element(owl_list *l, void *element)
+{
+  return owl_list_insert_element(l, 0, element);
+}
+
 int owl_list_remove_element(owl_list *l, int n)
 {
   int i;


home help back first fref pref prev next nref lref last post