Author: rfm
Date: Wed Jul 29 16:34:58 2015
New Revision: 38846

URL: http://svn.gna.org/viewcvs/gnustep?rev=38846&view=rev
Log:
Add a few methods

Modified:
    libs/performance/trunk/GSLinkedList.h
    libs/performance/trunk/GSLinkedList.m

Modified: libs/performance/trunk/GSLinkedList.h
URL: 
http://svn.gna.org/viewcvs/gnustep/libs/performance/trunk/GSLinkedList.h?rev=38846&r1=38845&r2=38846&view=diff
==============================================================================
--- libs/performance/trunk/GSLinkedList.h       (original)
+++ libs/performance/trunk/GSLinkedList.h       Wed Jul 29 16:34:58 2015
@@ -168,7 +168,10 @@
 }
 
 
-/** GSLinkedList manages a list of GSListLink objects.
+/** GSLinkedList manages a list of GSListLink objects.<br />
+ * The notional direction of the list is from head to tail. So the head
+ * is considered to be the first link in the list and tail is considered
+ * to be the last (head is before tail, tail is after head).
  */
 @interface     GSLinkedList : NSObject
 {
@@ -238,6 +241,8 @@
 
 /** Searches from list to the end looking for the first link containing
  * object (as determined by using object's [NSObject-isEqual:] method).<br />
+ * If back is YES, the search is in the direction from tail to head
+ * rather than the normal search from head to tail.<br />
  * If from is nil the list is search from head or tail as appropriate
  * to the direction in which it is searched.
  */
@@ -247,6 +252,8 @@
 
 /** Searches from list to the end looking for the first link containing
  * object (as determined by direct pointer comparison).<br />
+ * If back is YES, the search is in the direction from tail to head
+ * rather than the normal search from head to tail.<br />
  * If from is nil the list is search from head or tail as appropriate
  * to the direction in which it is searched.
  */
@@ -324,21 +331,21 @@
  */
 - (void) addObject: (id)anObject;
 
-/** Returns the first object in the list or nil if the list is empty.
+/** Returns the first (head) object in the list or nil if the list is empty.
  */
 - (id) firstObject;
 
 /** Inserts anObject immediately after the specified link.  If at is nil
- * the object is inserted at the end of the list.
+ * the object is inserted at the end of the list (as tail).
  */
 - (void) insertObject: (id)anObject after: (GSListLink*)at;
 
 /** Inserts anObject immediately before the specified link.  If at is nil
- * the object is inserted at the start of the list.
+ * the object is inserted at the start of the list (as head).
  */
 - (void) insertObject: (id)anObject before: (GSListLink*)at;
 
-/** Returns the last object in the list or nil if the list is empty.
+/** Returns the last (tail) object in the list or nil if the list is empty.
  */
 - (id) lastObject;
 
@@ -356,6 +363,15 @@
  * is empty).
  */
 - (void) removeLastObject;
+
+/** Removes the object in the specified link.
+ */
+- (void) removeObjectAt: (GSListLink*)at;
+
+/** Removes the object at the specified position.
+ */
+- (void) removeObjectAtIndex: (NSUInteger)index;
+
 @end
 
 /** Adds the object at the end of the list.

Modified: libs/performance/trunk/GSLinkedList.m
URL: 
http://svn.gna.org/viewcvs/gnustep/libs/performance/trunk/GSLinkedList.m?rev=38846&r1=38845&r2=38846&view=diff
==============================================================================
--- libs/performance/trunk/GSLinkedList.m       (original)
+++ libs/performance/trunk/GSLinkedList.m       Wed Jul 29 16:34:58 2015
@@ -278,24 +278,21 @@
 GSLinkedListFindEqual(NSObject *object, GSLinkedList *list,
   GSListLink *from, BOOL back)
 {
-  if (nil == from)
-    {
-      if (YES == back)
-       {
-         from = list->tail;
-       }
-      else
-       {
-         from = list->head;
-       }
-    }
-  if (nil != object)
+  if (nil == object)
+    {
+      return GSLinkedListFindIdentical(object, list, from, back);
+    }
+  else
     {
       BOOL     (*imp)(id, SEL, id);
 
       imp = (BOOL(*)(id,SEL,id))[object methodForSelector: 
@selector(isEqual:)];
       if (YES == back)
        {
+          if (nil == from)
+            {
+              from = list->tail;
+            }
          while (nil != from)
            {
              if (YES == (*imp)(object, @selector(isEqual:), from->item))
@@ -307,6 +304,10 @@
        }
       else
        {
+          if (nil == from)
+            {
+              from = list->head;
+            }
          while (nil != from)
            {
              if (YES == (*imp)(object, @selector(isEqual:), from->item))
@@ -325,19 +326,12 @@
 GSLinkedListFindIdentical(NSObject *object, GSLinkedList *list,
   GSListLink *from, BOOL back)
 {
-  if (nil == from)
-    {
-      if (YES == back)
-       {
+  if (YES == back)
+    {
+      if (nil == from)
+        {
          from = list->tail;
-       }
-      else
-       {
-         from = list->head;
-       }
-    }
-  if (YES == back)
-    {
+        }
       while (nil != from)
        {
          if (object == from->item)
@@ -349,6 +343,10 @@
     }
   else
     {
+      if (nil == from)
+        {
+          from = list->head;
+        }
       while (nil != from)
        {
          if (object == from->item)
@@ -545,7 +543,6 @@
 
       free = link->next;
       link->next = nil;
-      link->owner = nil;
       [link release];
     }
 }
@@ -564,6 +561,28 @@
     {
       GSLinkStoreRemoveObjectAt(self, tail);
     }
+}
+
+- (void) removeObjectAt: (GSListLink*)at
+{
+  GSLinkStoreRemoveObjectAt(self, at);
+}
+
+- (void) removeObjectAtIndex: (NSUInteger)index
+{
+  GSListLink    *link = head;
+
+  if (index >= count)
+    {
+      [NSException raise: NSInvalidArgumentException
+       format: @"[%@-%@] index too large",
+       NSStringFromClass([self class]), NSStringFromSelector(_cmd)];
+    }
+  while (index-- > 0)
+    {
+      link = link->next;
+    }
+  GSLinkStoreRemoveObjectAt(self, link);
 }
 
 @end
@@ -577,7 +596,6 @@
   if (nil == link)
     {
       link = [GSListLink new];
-      link->owner = list;
     }
   else
     {
@@ -597,7 +615,6 @@
   if (nil == link)
     {
       link = [GSListLink new];
-      link->owner = list;
     }
   else
     {


_______________________________________________
Gnustep-cvs mailing list
[email protected]
https://mail.gna.org/listinfo/gnustep-cvs

Reply via email to