discuss-gnustep
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

No sorter context in insertionPosition:


From: Alexander Malmberg
Subject: No sorter context in insertionPosition:
Date: Fri, 22 Feb 2002 02:39:07 +0100

Hi,

While trying to maintain a sorted NSMutableArray, I noticed that
[NSArray -insertionPosition: usingFunction:] expects a sorter function
without a third context parameter, unlike the functions passed to
-sortedArrayUsingFunction:. I'm guessing that this is just an oversight,
and I've attached a patch that fixes it (adds a context: parameter to
insertionPosition:... and the sorter function).

- Alexander Malmberg
Index: Headers/gnustep/base/NSArray.h
===================================================================
RCS file: /cvsroot/gnustep/gnustep/core/base/Headers/gnustep/base/NSArray.h,v
retrieving revision 1.38
diff -u -r1.38 NSArray.h
--- Headers/gnustep/base/NSArray.h      17 Dec 2001 14:31:41 -0000      1.38
+++ Headers/gnustep/base/NSArray.h      22 Feb 2002 01:31:22 -0000
@@ -148,7 +148,8 @@
  *     the reciever is 'less than' the item in the array.
  */
 - (unsigned) insertionPosition: (id)item
-                usingFunction: (NSComparisonResult (*)(id, id))sorter;
+                usingFunction: (NSComparisonResult (*)(id, id, void *))sorter
+                      context: (void *)context;
 - (unsigned) insertionPosition: (id)item
                 usingSelector: (SEL)comp;
 @end
Index: Source/GSArray.m
===================================================================
RCS file: /cvsroot/gnustep/gnustep/core/base/Source/GSArray.m,v
retrieving revision 1.6
diff -u -r1.6 GSArray.m
--- Source/GSArray.m    18 Dec 2001 16:18:18 -0000      1.6
+++ Source/GSArray.m    22 Feb 2002 01:31:22 -0000
@@ -739,7 +739,8 @@
  *      if it is greater, and NSOrderedSame if it is equal.
  */
 - (unsigned) insertionPosition: (id)item
-                usingFunction: (NSComparisonResult (*)(id, id))sorter
+                usingFunction: (NSComparisonResult (*)(id, id, void *))sorter
+                      context: (void *)context
 {
   unsigned     upper = _count;
   unsigned     lower = 0;
@@ -763,7 +764,7 @@
     {
       NSComparisonResult comparison;
 
-      comparison = (*sorter)(item, _contents_array[index]);
+      comparison = (*sorter)(item, _contents_array[index], context);
       if (comparison == NSOrderedAscending)
         {
           upper = index;
@@ -782,7 +783,7 @@
    *   items that are equal to the new one.
    */
   while (index < _count
-    && (*sorter)(item, _contents_array[index]) != NSOrderedAscending)
+    && (*sorter)(item, _contents_array[index], context) != NSOrderedAscending)
     {
       index++;
     }
Index: Source/NSArray.m
===================================================================
RCS file: /cvsroot/gnustep/gnustep/core/base/Source/NSArray.m,v
retrieving revision 1.105
diff -u -r1.105 NSArray.m
--- Source/NSArray.m    18 Dec 2001 16:54:14 -0000      1.105
+++ Source/NSArray.m    22 Feb 2002 01:31:23 -0000
@@ -1472,7 +1472,8 @@
  *      if it is greater, and NSOrderedSame if it is equal.
  */
 - (unsigned) insertionPosition: (id)item
-                usingFunction: (NSComparisonResult (*)(id, id))sorter
+                usingFunction: (NSComparisonResult (*)(id, id, void *))sorter
+                      context: (void *)context
 {
   unsigned     count = [self count];
   unsigned     upper = count;
@@ -1499,7 +1500,7 @@
     {
       NSComparisonResult comparison;
 
-      comparison = (*sorter)(item, (*oai)(self, oaiSel, index));
+      comparison = (*sorter)(item, (*oai)(self, oaiSel, index), context);
       if (comparison == NSOrderedAscending)
         {
           upper = index;
@@ -1518,7 +1519,7 @@
    *   items that are equal to the new one.
    */
   while (index < count
-    && (*sorter)(item, (*oai)(self, oaiSel, index)) != NSOrderedAscending)
+    && (*sorter)(item, (*oai)(self, oaiSel, index), context) != 
NSOrderedAscending)
     {
       index++;
     }

reply via email to

[Prev in Thread] Current Thread [Next in Thread]