Skip to content

Commit 96a4d79

Browse files
committed
Initial GSMinHeap implementation
1 parent 72c06b2 commit 96a4d79

11 files changed

Lines changed: 471 additions & 250 deletions

File tree

ChangeLog

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
1+
2026-07-14 Richard Frith-Macdonald <rfm@gnu.org>
2+
3+
* Headers/GNUstepBase/GSMinHeap.h:
4+
* Source/GSMinHeap.m:
5+
* Tests/base/GSMinHeap/test00.m:
6+
Implementation and tests for a minheap implementation.
7+
18
2026-07-11 Richard Frith-Macdonald <rfm@gnu.org>
29

310
* Source/NSAutoreleasePool.m: Changes to pass the thread autorelease

Headers/GNUstepBase/GSMinHeap.h

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
/** Interface for GSMinHeap class
2+
3+
Copyright (C) 2026 Free Software Foundation, Inc.
4+
5+
Written by: Richard Frith-Macdonald <rfm@gnu.org>
6+
7+
Date: July 2026
8+
9+
This file is part of the GNUstep Base Library.
10+
11+
This library is free software; you can redistribute it and/or
12+
modify it under the terms of the GNU Lesser General Public
13+
License as published by the Free Software Foundation; either
14+
version 2 of the License, or (at your option) any later version.
15+
16+
This library is distributed in the hope that it will be useful,
17+
but WITHOUT ANY WARRANTY; without even the implied warranty of
18+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19+
Library General Public License for more details.
20+
21+
You should have received a copy of the GNU Lesser General Public
22+
License along with this library; if not, write to the Free
23+
Software Foundation, Inc., 31 Milk Street #960789 Boston, MA 02196 USA.
24+
25+
AutogsdocSource: Additions/GSMinHeap.m
26+
*/
27+
28+
#ifndef __GSMinHeap_h_GNUSTEP_BASE_INCLUDE
29+
#define __GSMinHeap_h_GNUSTEP_BASE_INCLUDE
30+
#import <GNUstepBase/GSVersionMacros.h>
31+
32+
#if OS_API_VERSION(GS_API_NONE,GS_API_LATEST)
33+
34+
#import <Foundation/Foundation.h>
35+
36+
#if defined(__cplusplus)
37+
extern "C" {
38+
#endif
39+
40+
typedef NSComparisonResult (*GSMinHeapComparator)(id a, id b);
41+
42+
@interface GSMinHeap : NSObject
43+
{
44+
void *_internal;
45+
}
46+
/** Removes all objects from the heap.
47+
*/
48+
- (void) empty;
49+
50+
/** Initialises a heap with the specified capacity and comparator.<br />
51+
* If cap is zero the initial capacity is one item.<br />
52+
* If cmp is NULL the -compare: method is used as a comparator.<br />
53+
* If there is insufficient memory, the method returns nil.
54+
*/
55+
- (instancetype) initWithCapacity: (size_t)cap
56+
andComparator: (GSMinHeapComparator)cmp;
57+
58+
/** Returns the first object on the heap or nil if it is empty.
59+
*/
60+
- (id) peek;
61+
62+
/** Removes the first object from the heap and returns it. Returns nil
63+
* if the heap was already empty.
64+
*/
65+
- (id) pop;
66+
67+
/** Adds obj to the heap and returns YES on success. May return NO on failure
68+
* (of obj was nil or if there is insufficient memory for the heap to grow).
69+
*/
70+
- (BOOL) push: (id)obj;
71+
@end
72+
73+
74+
#if defined(__cplusplus)
75+
}
76+
#endif
77+
78+
#endif /* OS_API_VERSION(GS_API_NONE,GS_API_NONE) */
79+
80+
#endif /* __GSMinHeap_h_GNUSTEP_BASE_INCLUDE */

Headers/GNUstepBase/GSTree.h

Lines changed: 0 additions & 93 deletions
This file was deleted.

Source/Additions/GNUmakefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ Additions_OBJC_FILES =\
4141
GSFunctions.m \
4242
GSInsensitiveDictionary.m \
4343
GSMime.m \
44+
GSMinHeap.m \
4445
GSURITemplate.m \
4546
GSXML.m \
4647
NSArray+GNUstepBase.m \

0 commit comments

Comments
 (0)