|
| 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 */ |
0 commit comments