Second patch from Albin Jones

git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@1240 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
Andrew McCallum 1996-03-22 00:36:13 +00:00
parent 957502e2dd
commit 17de3bd4bc
60 changed files with 3935 additions and 9729 deletions

View file

@ -317,3 +317,74 @@ of union alternative is controlled by a previous structure component.
(See gcc @samp{PROJECTS} file.)
@end itemize
@section Albin's To Do List
I'm sure that there're other things to do, but these are the ones I know now:
@subsection General
@itemize @bullet
@item Make thread-safe all of my code that should be.
@item Fully annotate all of my headers.
@item Document my work and the use of its fruit.
@end itemize
@subsection Critical
@itemize @bullet
@item Code:
@itemize +
@item (@file{src/array.m}) @samp{objects_array_check}
@item (@file{src/array.m}) @samp{objects_array_map_elements}
@item (@file{src/cbs-char-p.m}) @samp{objects_char_p_describe}
@item (@file{src/cbs-int-p.m}) @samp{objects_int_p_describe}
@item (@file{src/cbs-int.m}) @samp{objects_int_describe}
@item (@file{src/hash.m}) @samp{_objects_hash_hash}
@item (@file{src/hash.m}) @samp{objects_hash_check}
@item (@file{src/hash.m}) @samp{objects_hash_description}
@item (@file{src/list.m}) @samp{objects_list_is_equal_to_list}
@item (@file{src/map.m}) @samp{_objects_map_hash}
@item (@file{src/map.m}) @samp{objects_map_check}
@item (@file{src/map.m}) @samp{objects_map_description}
@end itemize
@item Correct:
@itemize +
@item (@file{src/array.m}) @samp{objects_array_dealloc}
@item (@file{src/cbs-int.m}) @samp{_OBJECTS_NOT_AN_INT_MARKER}
@end itemize
@item Improve the error handling of:
@itemize +
@item (@file{src/array.m}) @samp{_objects_array_insert_bucket}
@item (@file{src/hash.m}) @samp{objects_hash_add_element_known_absent}
@item (@file{src/list.m}) @samp{objects_list_at_index_insert_element}
@item (@file{src/map.m}) @samp{objects_map_at_key_put_value_known_absent}
@end itemize
@end itemize
@subsection Not So Critical
@itemize @bullet
@item Strengthen my resolve on the correctness of:
@itemize +
@item (@file{src/cbs-char-p.m}) @samp{_OBJECTS_NOT_A_CHAR_P_MARKER}
@item (@file{src/cbs-id.m}) @samp{_OBJECTS_NOT_AN_ID_MARKER}
@item (@file{src/cbs-int-p.m}) @samp{_OBJECTS_NOT_AN_INT_P_MARKER}
@item (@file{src/cbs-int-p.m}) @samp{objects_int_p_is_equal}
@item (@file{src/cbs-void-p.m}) @samp{_OBJECTS_NOT_A_VOID_P_MARKER}
@item (@file{src/hash.m}) @samp{objects_hash_rightsize}
@item (@file{src/hash.m}) @samp{objects_hash_all_elements}
@item (@file{src/map.m}) @samp{objects_map_rightsize}
@item (@file{src/map.m}) @samp{objects_map_all_keys}
@item (@file{src/map.m}) @samp{objects_map_all_values}
@end itemize
@item Improve the effeciency of:
@itemize +
@item (@file{src/array.m}) @samp{_objects_array_insert_bucket}
@item (@file{src/hash.m}) @samp{objects_hash_minus_hash}
@item (@file{src/list.m}) @samp{objects_list_at_index_insert_list}
@end itemize
@end itemize

View file

@ -1,96 +1,223 @@
/* Interface for NSGeometry routines for GNUStep
Copyright (C) 1995 Free Software Foundation, Inc.
Written by: Adam Fedor <fedor@boulder.colorado.edu>
Date: 1995
This file is part of the GNU Objective C Class Library.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public
License along with this library; if not, write to the Free
Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
* Copyright (C) 1995 Free Software Foundation, Inc.
*
* Written by: Adam Fedor <fedor@boulder.colorado.edu>
* Date: 1995
*
* This file is part of the GNU Objective C Class Library.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the Free
* Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
#ifndef __NSGeometry_h_OBJECTS_INCLUDE
#define __NSGeometry_h_OBJECTS_INCLUDE
/**** Included Headers *******************************************************/
#include <objc/objc.h>
#include <Foundation/NSString.h>
/* Geometry */
/**** Type, Constant, and Macro Definitions **********************************/
typedef struct _NSPoint { /* Point definition. */
float x;
float y;
} NSPoint;
typedef struct _NSSize { /* Rectangle sizes. */
float width;
float height;
} NSSize;
/* Point definition. */
typedef struct _NSPoint NSPoint;
struct _NSPoint
{
float x;
float y;
};
typedef struct _NSRect { /* Rectangle. */
NSPoint origin;
NSSize size;
} NSRect;
/* Rectangle sizes. */
typedef struct _NSSize NSSize;
struct _NSSize
{
float width;
float height;
};
typedef enum {
NSMinXEdge,
NSMinYEdge,
NSMaxXEdge,
NSMaxYEdge
} NSRectEdge;
/* Rectangle. */
typedef struct _NSRect NSRect;
struct _NSRect
{
NSPoint origin;
NSSize size;
};
/* Standard zero structures */
const NSPoint NSZeroPoint;
const NSRect NSZeroRect;
const NSSize NSZeroSize;
/* Sides of a rectangle. */
typedef enum _NSRectEdge NSRectEdge;
enum _NSRectEdge
{
NSMinXEdge,
NSMinYEdge,
NSMaxXEdge,
NSMaxYEdge
};
/* Create Basic Structures */
extern NSPoint NSMakePoint(float x, float y);
extern NSSize NSMakeSize(float w, float h);
extern NSRect NSMakeRect(float x, float y, float w, float h);
const NSPoint NSZeroPoint; /* A zero point. */
const NSRect NSZeroRect; /* A zero origin rectangle. */
const NSSize NSZeroSize; /* A zero size rectangle. */
/* Get rectangle coordinates */
extern float NSMaxX(NSRect aRect);
extern float NSMaxY(NSRect aRect);
extern float NSMidX(NSRect aRect);
extern float NSMidY(NSRect aRect);
extern float NSMinX(NSRect aRect);
extern float NSMinY(NSRect aRect);
extern float NSWidth(NSRect aRect);
extern float NSHeight(NSRect aRect);
/**** Function Prototypes ****************************************************/
/* Modify a copy of a rectangle */
extern NSRect NSOffsetRect(NSRect aRect, float dx, float dy);
extern NSRect NSInsetRect(NSRect aRect, float dX, float dY);
extern NSRect NSIntegralRect(NSRect aRect);
extern void NSDivideRect(NSRect aRect, NSRect *slice, NSRect *remainder,
float amount, NSRectEdge edge);
/** Create Basic Structures... **/
/* Compute a third rectangle from two rectangles */
extern NSRect NSUnionRect(NSRect aRect, NSRect bRect);
extern NSRect NSIntersectionRect (NSRect aRect, NSRect bRect);
/* Returns an NSPoint having x-coordinate X and y-coordinate Y. */
extern NSPoint
NSMakePoint(float x, float y);
/* Returns an NSSize having width WIDTH and height HEIGHT. */
extern NSSize
NSMakeSize(float w, float h);
/* Test geometrical relationships */
extern BOOL NSEqualRects(NSRect aRect, NSRect bRect);
extern BOOL NSEqualSizes(NSSize aSize, NSSize bSize);
extern BOOL NSEqualPoints(NSPoint aPoint, NSPoint bPoint);
extern BOOL NSIsEmptyRect(NSRect aRect);
extern BOOL NSMouseInRect(NSPoint aPoint, NSRect aRect, BOOL flipped);
extern BOOL NSPointInRect(NSPoint aPoint, NSRect aRect);
extern BOOL NSContainsRect(NSRect aRect, NSRect bRect);
/* Returns an NSRect having point of origin (X, Y) and size {W, H}. */
extern NSRect
NSMakeRect(float x, float y, float w, float h);
extern BOOL NSIntersectsRect (NSRect aRect, NSRect bRect);
/** Get a Rectangle's Coordinates... **/
/* Returns the greatest x-coordinate value still inside ARECT. */
extern float
NSMaxX(NSRect aRect);
/* Returns the greatest y-coordinate value still inside ARECT. */
extern float
NSMaxY(NSRect aRect);
/* Returns the x-coordinate of ARECT's middle point. */
extern float
NSMidX(NSRect aRect);
/* Returns the y-coordinate of ARECT's middle point. */
extern float
NSMidY(NSRect aRect);
/* Returns the least x-coordinate value still inside ARECT. */
extern float
NSMinX(NSRect aRect);
/* Returns the least y-coordinate value still inside ARECT. */
extern float
NSMinY(NSRect aRect);
/* Returns ARECT's width. */
extern float
NSWidth(NSRect aRect);
/* Returns ARECT's height. */
extern float
NSHeight(NSRect aRect);
/** Modify a Copy of a Rectangle... **/
/* Returns the rectangle obtained by moving each of ARECT's
* horizontal sides inward by DY and each of ARECT's vertical
* sides inward by DX. */
extern NSRect
NSInsetRect(NSRect aRect, float dX, float dY);
/* Returns the rectangle obtained by translating ARECT
* horizontally by DX and vertically by DY. */
extern NSRect
NSOffsetRect(NSRect aRect, float dx, float dy);
/* Divides ARECT into two rectangles (namely SLICE and REMAINDER) by
* "cutting" ARECT---parallel to, and a distance AMOUNT from the edge
* of ARECT determined by EDGE. You may pass 0 in as either of SLICE or
* REMAINDER to avoid obtaining either of the created rectangles. */
extern void
NSDivideRect(NSRect aRect,
NSRect *slice,
NSRect *remainder,
float amount,
NSRectEdge edge);
/* Returns a rectangle obtained by expanding ARECT minimally
* so that all four of its defining components are integers. */
extern NSRect
NSIntegralRect(NSRect aRect);
/** Compute a Third Rectangle from Two Rectangles... **/
/* Returns the smallest rectangle which contains both ARECT
* and BRECT (modulo a set of measure zero). If either of ARECT
* or BRECT is an empty rectangle, then the other rectangle is
* returned. If both are empty, then the empty rectangle is returned. */
extern NSRect
NSUnionRect(NSRect aRect, NSRect bRect);
/* Returns the largest rectange which lies in both ARECT and
* BRECT. If ARECT and BRECT have empty intersection (or, rather,
* intersection of measure zero, since this includes having their
* intersection be only a point or a line), then the empty
* rectangle is returned. */
extern NSRect
NSIntersectionRect(NSRect aRect, NSRect bRect);
/** Test geometric relationships... **/
/* Returns 'YES' iff ARECT's and BRECT's origin and size are the same. */
extern BOOL
NSEqualRects(NSRect aRect, NSRect bRect);
/* Returns 'YES' iff ASIZE's and BSIZE's width and height are the same. */
extern BOOL
NSEqualSizes(NSSize aSize, NSSize bSize);
/* Returns 'YES' iff APOINT's and BPOINT's x- and y-coordinates
* are the same. */
extern BOOL
NSEqualPoints(NSPoint aPoint, NSPoint bPoint);
/* Returns 'YES' iff the area of ARECT is zero (i.e., iff either
* of ARECT's width or height is negative or zero). */
extern BOOL
NSIsEmptyRect(NSRect aRect);
/* Returns 'YES' iff APOINT is inside ARECT. */
extern BOOL
NSMouseInRect(NSPoint aPoint, NSRect aRect, BOOL flipped);
/* Just like 'NSMouseInRect(aPoint, aRect, YES)'. */
extern BOOL
NSPointInRect(NSPoint aPoint, NSRect aRect);
/* Returns 'YES' iff ARECT totally encloses BRECT. NOTE: For
* this to be the case, ARECT cannot be empty, nor can any side
* of BRECT coincide with any side of ARECT. */
extern BOOL
NSContainsRect(NSRect aRect, NSRect bRect);
/* FIXME: This function isn't listed in the OpenStep Specification. */
extern BOOL
NSIntersectsRect(NSRect aRect, NSRect bRect);
/** Get a String Representation... **/
/* Returns an NSString of the form "{x=X; y=Y}", where
* X and Y are the x- and y-coordinates of APOINT, respectively. */
extern NSString *
NSStringFromPoint(NSPoint aPoint);
/* Returns an NSString of the form "{x=X; y=Y; width=W; height=H}",
* where X, Y, W, and H are the x-coordinate, y-coordinate,
* width, and height of ARECT, respectively. */
extern NSString *
NSStringFromRect(NSRect aRect);
/* Returns an NSString of the form "{width=W; height=H}", where
* W and H are the width and height of ASIZE, respectively. */
extern NSString *
NSStringFromSize(NSSize aSize);
#endif /* __NSGeometry_h_OBJECTS_INCLUDE */

View file

@ -3,8 +3,8 @@
*
* Author: Albin L. Jones <Albin.L.Jones@Dartmouth.EDU>
* Created: Mon Dec 12 23:56:03 EST 1994
* Updated: Sat Feb 10 15:55:51 EST 1996
* Serial: 96.02.10.02
* Updated: Thu Mar 21 15:13:46 EST 1996
* Serial: 96.03.21.06
*
* This file is part of the GNU Objective C Class Library.
*
@ -20,9 +20,7 @@
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the Free
* Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*
*/
* Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
#ifndef __NSHashTable_h_OBJECTS_INCLUDE
#define __NSHashTable_h_OBJECTS_INCLUDE 1
@ -36,77 +34,165 @@
/**** Type, Constant, and Macro Definitions **********************************/
/* Hash table type. */
typedef objects_hash_t NSHashTable;
typedef objects_hash_enumerator_t NSHashEnumerator;
typedef struct _NSHashTableCallBacks NSHashTableCallBacks;
/* Private type for enumerating. */
typedef objects_hash_enumerator_t NSHashEnumerator;
/* Callback functions. */
typedef struct _NSHashTableCallBacks NSHashTableCallBacks;
struct _NSHashTableCallBacks
{
unsigned int (*hash) (NSHashTable *, const void *);
BOOL (*isEqual) (NSHashTable *, const void *, const void *);
void (*retain) (NSHashTable *, const void *);
void (*release) (NSHashTable *, void *);
NSString *(*describe) (NSHashTable *, const void *);
/* Hashing function. NOTE: Elements with equal values must have
* equal hash function values. */
unsigned int (*hash)(NSHashTable *, const void *);
/* Comparison function. */
BOOL (*isEqual)(NSHashTable *, const void *, const void *);
/* Retaining function called when adding elements to table. */
void (*retain)(NSHashTable *, const void *);
/* Releasing function called when a data element is
* removed from the table. */
void (*release)(NSHashTable *, void *);
/* Description function. */
NSString *(*describe)(NSHashTable *, const void *);
};
/* For sets of pointer-sized or smaller quantities. */
extern const NSHashTableCallBacks NSIntHashCallBacks;
/* For sets of pointers hashed by address. */
extern const NSHashTableCallBacks NSNonOwnedPointerHashCallBacks;
/* For sets of objects without retaining and releasing. */
extern const NSHashTableCallBacks NSNonRetainedObjectsHashCallBacks;
/* For sets of objects; similar to NSSet. */
extern const NSHashTableCallBacks NSObjectsHashCallBacks;
/* For sets of pointers with transfer of ownership upon insertion. */
extern const NSHashTableCallBacks NSOwnedPointerHashCallBacks;
/* For sets of pointers to structs when the first field of the
* struct is the size of an int. */
extern const NSHashTableCallBacks NSPointerToStructHashCallBacks;
/**** Function Prototypes ****************************************************/
/** Creating an NSHashTable **/
/** Creating an NSHashTable... **/
NSHashTable *NSCreateHashTable (NSHashTableCallBacks callBacks,
unsigned int capacity);
/* Returns a (pointer to) an NSHashTable space for which is allocated
* in the default zone. If CAPACITY is small or 0, then the returned
* table has a reasonable (but still small) capacity. */
NSHashTable *
NSCreateHashTable(NSHashTableCallBacks callBacks,
unsigned int capacity);
NSHashTable *NSCreateHashTableWithZone (NSHashTableCallBacks callBacks,
unsigned int capacity,
NSZone *zone);
/* Just like 'NSCreateHashTable()', but the returned hash table is created
* in the memory zone ZONE, rather than in the default zone. (Of course,
* if you send 0 for ZONE, then the hash table will be created in the
* default zone.) */
NSHashTable *
NSCreateHashTableWithZone(NSHashTableCallBacks callBacks,
unsigned int capacity,
NSZone *zone);
NSHashTable *NSCopyHashTableWithZone (NSHashTable *table, NSZone *zone);
/* Returns a hash table, space for which is allocated in ZONE, which
* has (newly retained) copies of TABLE's keys and values. As always,
* if ZONE is 0, then the returned hash table is allocated in the
* default zone. */
NSHashTable *
NSCopyHashTableWithZone(NSHashTable *table, NSZone *zone);
/** Freeing an NSHashTable **/
/** Freeing an NSHashTable... **/
void NSFreeHashTable (NSHashTable * table);
/* Releases all the keys and values of TABLE (using the callbacks
* specified at the time of TABLE's creation), and then proceeds
* to deallocate the space allocated for TABLE itself. */
void
NSFreeHashTable(NSHashTable *table);
void NSResetHashTable (NSHashTable * table);
/* Releases every element of TABLE, while preserving
* TABLE's "capacity". */
void
NSResetHashTable(NSHashTable *table);
/** Comparing two NSHashTables **/
/** Comparing two NSHashTables... **/
BOOL NSCompareHashTables (NSHashTable *table1, NSHashTable *table2);
/* Returns 'YES' if and only if every element of TABLE1 is an element
* of TABLE2, and vice versa. */
BOOL
NSCompareHashTables(NSHashTable *table1, NSHashTable *table2);
/** Getting the number of items in an NSHashTable **/
/** Getting the number of items in an NSHashTable... **/
unsigned int NSCountHashTable (NSHashTable *table);
/* Returns the total number of elements in TABLE. */
unsigned int
NSCountHashTable(NSHashTable *table);
/** Retrieving items from an NSHashTable **/
/** Retrieving items from an NSHashTable... **/
void *NSHashGet (NSHashTable *table, const void *pointer);
/* Returns the element of TABLE equal to POINTER, if POINTER is a
* member of TABLE. If not, then 0 (the only completely
* forbidden element) is returned. */
void *
NSHashGet(NSHashTable *table, const void *pointer);
NSArray *NSAllHashTableObjects (NSHashTable *table);
/* Returns an NSArray which contains all of the elements of TABLE.
* WARNING: Call this function only when the elements of TABLE
* are objects. */
NSArray *
NSAllHashTableObjects(NSHashTable *table);
NSHashEnumerator NSEnumerateHashTable (NSHashTable *table);
/* Returns an NSHashEnumerator structure (a pointer to) which
* can be passed repeatedly to the function 'NSNextHashEnumeratorItem()'
* to enumerate the elements of TABLE. */
NSHashEnumerator
NSEnumerateHashTable(NSHashTable *table);
void *NSNextHashEnumeratorItem (NSHashEnumerator *enumerator);
/* Return 0 if ENUMERATOR has completed its enumeration of
* its hash table's elements. If not, then the next element is
* returned. */
void *
NSNextHashEnumeratorItem(NSHashEnumerator *enumerator);
/** Adding an item to an NSHashTable **/
/** Adding an item to an NSHashTable... **/
void NSHashInsert (NSHashTable *table, const void *pointer);
/* Inserts the item POINTER into the hash table TABLE.
* If POINTER is already an element of TABLE, then its previously
* incarnation is released from TABLE, and POINTER is put in its place.
* Raises an NSInvalidArgumentException if POINTER is 0. */
void
NSHashInsert(NSHashTable *table, const void *pointer);
void NSHashInsertKnownAbsent (NSHashTable *table, const void *pointer);
/* Just like 'NSHashInsert()', with one exception: If POINTER is already
* in TABLE, then an NSInvalidArgumentException is raised. */
void
NSHashInsertKnownAbsent(NSHashTable *table, const void *pointer);
void *NSHashInsertIfAbsent (NSHashTable *table, const void *pointer);
/* If POINTER is already in TABLE, the pre-existing item is returned.
* Otherwise, 0 is returned, and this is just like 'NSHashInsert()'. */
void *
NSHashInsertIfAbsent(NSHashTable *table, const void *pointer);
/** Removing an item from an NSHashTable **/
/** Removing an item from an NSHashTable... **/
void NSHashRemove (NSHashTable *table, const void *pointer);
/* Releases POINTER from TABLE. It is not
* an error if POINTER is not already in TABLE. */
void
NSHashRemove(NSHashTable *table, const void *pointer);
/** Getting an NSString representation of an NSHashTable **/
/** Getting an NSString representation of an NSHashTable... **/
NSString *NSStringFromHashTable (NSHashTable *table);
/* Returns an NSString which describes TABLE. The returned string
* is produced by iterating over the elements of TABLE,
* appending the string "X;\n", where X is the description of
* the element (obtained from the callbacks, of course). */
NSString *
NSStringFromHashTable(NSHashTable *table);
#endif /* __NSHashTable_h_OBJECTS_INCLUDE */

View file

@ -3,8 +3,8 @@
*
* Author: Albin L. Jones <Albin.L.Jones@Dartmouth.EDU>
* Created: Tue Dec 13 00:05:02 EST 1994
* Updated: Sat Feb 10 15:55:51 EST 1996
* Serial: 96.02.10.02
* Updated: Thu Mar 21 15:12:42 EST 1996
* Serial: 96.03.21.05
*
* This file is part of the GNU Objective C Class Library.
*
@ -20,9 +20,7 @@
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the Free
* Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*
*/
* Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
#ifndef __NSMapTable_h_OBJECTS_INCLUDE
#define __NSMapTable_h_OBJECTS_INCLUDE 1
@ -36,109 +34,222 @@
/**** Type, Constant, and Macro Definitions **********************************/
/* Map table type. */
typedef objects_map_t NSMapTable;
typedef objects_map_enumerator_t NSMapEnumerator;
typedef struct _NSMapTableKeyCallBacks NSMapTableKeyCallBacks;
typedef struct _NSMapTableValueCallBacks NSMapTableValueCallBacks;
/* Private type for enumerating. */
typedef objects_map_enumerator_t NSMapEnumerator;
/* Callback functions for a key. */
typedef struct _NSMapTableKeyCallBacks NSMapTableKeyCallBacks;
struct _NSMapTableKeyCallBacks
{
unsigned (*hash) (NSMapTable *, const void *);
BOOL (*isEqual) (NSMapTable *, const void *, const void *);
void (*retain) (NSMapTable *, const void *);
void (*release) (NSMapTable *, void *);
NSString *(*describe) (NSMapTable *, const void *);
/* Hashing function. NOTE: Elements with equal values must
* have equal hash function values. */
unsigned (*hash)(NSMapTable *, const void *);
/* Comparison function. */
BOOL (*isEqual)(NSMapTable *, const void *, const void *);
/* Retaining function called when adding elements to table. */
void (*retain)(NSMapTable *, const void *);
/* Releasing function called when a data element is
* removed from the table. */
void (*release)(NSMapTable *, void *);
/* Description function. */
NSString *(*describe)(NSMapTable *, const void *);
/* Quantity that is not a key to the map table. */
const void *notAKeyMarker;
};
/* Callback functions for a value. */
typedef struct _NSMapTableValueCallBacks NSMapTableValueCallBacks;
struct _NSMapTableValueCallBacks
{
void (*retain) (NSMapTable *, const void *);
void (*release) (NSMapTable *, void *);
NSString *(*describe) (NSMapTable *, const void *);
/* Retaining function called when adding elements to table. */
void (*retain)(NSMapTable *, const void *);
/* Releasing function called when a data element is
* removed from the table. */
void (*release)(NSMapTable *, void *);
/* Description function. */
NSString *(*describe)(NSMapTable *, const void *);
};
/* FIXME: What to do here? These can't be right. */
#define NSNotAnIntMapKey 0
#define NSNotAPointerMapKey NULL
/* Quantities that are never map keys. */
#define NSNotAnIntMapKey objects_not_an_int_marker
#define NSNotAPointerMapKey objects_not_a_void_p_marker
/* For keys that are pointer-sized or smaller quantities. */
extern const NSMapTableKeyCallBacks NSIntMapKeyCallBacks;
/* For keys that are pointers not freed. */
extern const NSMapTableKeyCallBacks NSNonOwnedPointerMapKeyCallBacks;
/* For keys that are pointers not freed, or 0. */
extern const NSMapTableKeyCallBacks NSNonOwnedPointerOrNullMapKeyCallBacks;
/* For sets of objects without retaining and releasing. */
extern const NSMapTableKeyCallBacks NSNonRetainedObjectMapKeyCallBacks;
/* For keys that are objects. */
extern const NSMapTableKeyCallBacks NSObjectMapKeyCallBacks;
/* For keys that are pointers with transfer of ownership upon insertion. */
extern const NSMapTableKeyCallBacks NSOwnedPointerMapKeyCallBacks;
/* For values that are pointer-sized quantities. */
extern const NSMapTableValueCallBacks NSIntMapValueCallBacks;
/* For values that are pointers not freed. */
extern const NSMapTableValueCallBacks NSNonOwnedPointerMapValueCallBacks;
/* For values that are objects. */
extern const NSMapTableValueCallBacks NSObjectMapValueCallBacks;
/* For values that are pointers with transfer of ownership upon insertion. */
extern const NSMapTableValueCallBacks NSOwnedPointerMapValueCallBacks;
/**** Function Prototypes ****************************************************/
/** Creating an NSMapTable **/
/** Creating an NSMapTable... **/
NSMapTable *NSCreateMapTable (NSMapTableKeyCallBacks keyCallBacks,
NSMapTableValueCallBacks valueCallBacks,
unsigned int capacity);
/* Returns a (pointer to) an NSMapTable space for which is allocated
* in the default zone. If CAPACITY is small or 0, then the returned
* table has a reasonable capacity. */
NSMapTable *
NSCreateMapTable(NSMapTableKeyCallBacks keyCallBacks,
NSMapTableValueCallBacks valueCallBacks,
unsigned int capacity);
NSMapTable *NSCreateMapTableWithZone (NSMapTableKeyCallBacks keyCallBacks,
NSMapTableValueCallBacks valueCallbacks,
unsigned int capacity,
NSZone *zone);
/* Just like 'NSCreateMapTable()', but the returned map table is created
* in the memory zone ZONE, rather than in the default zone. (Of course,
* if you send 0 for ZONE, then the map table will be created in the
* default zone.) */
NSMapTable *
NSCreateMapTableWithZone(NSMapTableKeyCallBacks keyCallBacks,
NSMapTableValueCallBacks valueCallbacks,
unsigned int capacity,
NSZone *zone);
NSMapTable *NSCopyMapTableWithZone (NSMapTable *table,
NSZone *zone);
/* Returns a map table, space for which is allocated in ZONE, which
* has (newly retained) copies of TABLE's keys and values. As always,
* if ZONE is 0, then the returned map table is allocated in the
* default zone. */
NSMapTable *
NSCopyMapTableWithZone(NSMapTable *table, NSZone *zone);
/** Freeing an NSMapTable **/
/** Freeing an NSMapTable... **/
void NSFreeMapTable (NSMapTable *table);
/* Releases all the keys and values of TABLE (using the key and
* value callbacks specified at the time of TABLE's creation),
* and then proceeds to deallocate the space allocated for TABLE itself. */
void
NSFreeMapTable(NSMapTable *table);
void NSResetMapTable (NSMapTable *table);
/* Releases every key and value of TABLE, while preserving
* TABLE's "capacity". */
void
NSResetMapTable(NSMapTable *table);
/** Comparing two NSMapTables **/
/** Comparing two NSMapTables... **/
BOOL NSCompareMapTables (NSMapTable *table1, NSMapTable *table2);
/* Returns 'YES' if and only if every key of TABLE1 is a key
* of TABLE2, and vice versa. NOTE: This function only cares
* about keys, never values. */
BOOL
NSCompareMapTables(NSMapTable *table1, NSMapTable *table2);
/** Getting the number of items in an NSMapTable **/
/** Getting the number of items in an NSMapTable... **/
unsigned int NSCountMapTable (NSMapTable *table);
/* Returns the total number of key/value pairs in TABLE. */
unsigned int
NSCountMapTable(NSMapTable *table);
/** Retrieving items from an NSMapTable **/
/** Retrieving items from an NSMapTable... **/
BOOL NSMapMember (NSMapTable *table, const void *key,
void **originalKey, void **value);
/* Returns 'YES' iff TABLE contains a key that is "equal" to KEY.
* If so, then ORIGINALKEY is set to that key of TABLE, while
* VALUE is set to the value to which it maps in TABLE. */
BOOL
NSMapMember(NSMapTable *table,
const void *key,
void **originalKey,
void **value);
void *NSMapGet (NSMapTable *table, const void *key);
/* Returns the value to which TABLE maps KEY, if KEY is a
* member of TABLE. If not, then 0 (the only completely
* forbidden value) is returned. */
void *
NSMapGet(NSMapTable *table, const void *key);
NSMapEnumerator NSEnumerateMapTable (NSMapTable *table);
/* Returns an NSMapEnumerator structure (a pointer to) which
* can be passed repeatedly to the function 'NSNextMapEnumeratorPair()'
* to enumerate the key/value pairs of TABLE. */
NSMapEnumerator
NSEnumerateMapTable(NSMapTable *table);
BOOL NSNextMapEnumeratorPair (NSMapEnumerator *enumerator,
void **key,
void **value);
/* Return 'NO' if ENUMERATOR has completed its enumeration of
* its map table's key/value pairs. If not, then 'YES' is
* returned and KEY and VALUE are set to the next key and
* value (respectively) in ENUMERATOR's table. */
BOOL
NSNextMapEnumeratorPair(NSMapEnumerator *enumerator,
void **key,
void **value);
NSArray *NSAllMapTableKeys (NSMapTable *table);
/* Returns an NSArray which contains all of the keys of TABLE.
* WARNING: Call this function only when the keys of TABLE
* are objects. */
NSArray *
NSAllMapTableKeys(NSMapTable *table);
NSArray *NSAllMapTableValues (NSMapTable *table);
/* Returns an NSArray which contains all of the values of TABLE.
* WARNING: Call this function only when the values of TABLE
* are objects. */
NSArray *
NSAllMapTableValues(NSMapTable *table);
/** Adding an item to an NSMapTable **/
/** Adding an item to an NSMapTable... **/
void NSMapInsert (NSMapTable *table, const void *key, const void *value);
/* Inserts the association KEY -> VALUE into the map table TABLE.
* If KEY is already a key of TABLE, then its previously associated
* value is released from TABLE, and VALUE is put in its place.
* Raises an NSInvalidArgumentException if KEY is the "not a key
* marker" for TABLE (as specified in its key callbacks). */
void
NSMapInsert(NSMapTable *table, const void *key, const void *value);
void *NSMapInsertIfAbsent (NSMapTable *table,
const void *key,
const void *value);
/* If KEY is already in TABLE, the pre-existing key is returned.
* Otherwise, 0 is returned, and this is just like 'NSMapInsert()'. */
void *
NSMapInsertIfAbsent(NSMapTable *table, const void *key, const void *value);
void NSMapInsertKnownAbsent (NSMapTable *table,
const void *key,
const void *value);
/* Just like 'NSMapInsert()', with one exception: If KEY is already
* in TABLE, then an NSInvalidArgumentException is raised. */
void
NSMapInsertKnownAbsent(NSMapTable *table,
const void *key,
const void *value);
/** Removing an item from an NSMapTable **/
/** Removing an item from an NSMapTable... **/
void NSMapRemove (NSMapTable *table, const void *key);
/* Releases KEY (and its associated value) from TABLE. It is not
* an error if KEY is not already in TABLE. */
void
NSMapRemove(NSMapTable *table, const void *key);
/** Getting an NSString representation of an NSMapTable **/
/* Returns an NSString which describes TABLE. The returned string
* is produced by iterating over the key/value pairs of TABLE,
* appending the string "X = Y;\n", where X is the description of
* the key, and Y is the description of the value (each obtained
* from the respective callbacks, of course). */
NSString *NSStringFromMapTable (NSMapTable *table);
#endif /* __NSMapTable_h_OBJECTS_INCLUDE */

View file

@ -1,37 +1,42 @@
/* Interface for NSObject for GNUStep
Copyright (C) 1995 Free Software Foundation, Inc.
Written by: R. Andrew McCallum <mccallum@gnu.ai.mit.edu>
Date: 1995
This file is part of the GNU Objective C Class Library.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public
License along with this library; if not, write to the Free
Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
* Copyright (C) 1995 Free Software Foundation, Inc.
*
* Written by: Adam Fedor <fedor@boulder.colorado.edu>
* Date: 1995
*
* This file is part of the GNU Objective C Class Library.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the Free
* Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
#ifndef __NSRange_h_OBJECTS_INCLUDE
#define __NSRange_h_OBJECTS_INCLUDE
/**** Included Headers *******************************************************/
#include <Foundation/NSObject.h>
typedef struct _NSRange
/**** Type, Constant, and Macro Definitions **********************************/
typedef struct _NSRange NSRange;
struct _NSRange
{
unsigned int location;
unsigned int length;
} NSRange;
};
/**** Function Prototypes ****************************************************/
static inline unsigned
NSMaxRange(NSRange range) __attribute__ ((unused));
@ -51,13 +56,19 @@ NSLocationInRange(unsigned location, NSRange range)
return (location >= range.location) && (location < NSMaxRange(range));
}
extern NSRange NSMakeRange(float location, float length);
/* Create an NSRange having the specified LOCATION and LENGTH. */
extern NSRange
NSMakeRange(float location, float length);
extern NSRange NSUnionRange(NSRange range1, NSRange range2);
extern NSRange
NSUnionRange(NSRange range1, NSRange range2);
extern NSRange NSIntersectionRange(NSRange range1, NSRange range2);
extern NSRange
NSIntersectionRange(NSRange range1, NSRange range2);
@class NSString;
extern NSString *NSStringFromRange(NSRange range);
extern NSString *
NSStringFromRange(NSRange range);
#endif /* __NSRange_h_OBJECTS_INCLUDE */

View file

@ -1,41 +0,0 @@
/* A hookable abort function for Libobjects.
* Copyright (C) 1993, 1994, 1995, 1996 Free Software Foundation, Inc.
*
* Author: Albin L. Jones <Albin.L.Jones@Dartmouth.EDU>
* Created: Sat Feb 10 12:34:27 EST 1996
* Updated: Sat Feb 10 15:49:43 EST 1996
* Serial: 96.02.10.03
*
* This file is part of the GNU Objective C Class Library.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the Free
* Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*
*/
#ifndef __abort_h_OBJECTS_INCLUDE
#define __abort_h_OBJECTS_INCLUDE 1
/**** Included Headers *******************************************************/
/**** Type, Constant, and Macro Definitions **********************************/
extern void (*__objects_abort) (void);
/**** Function Prototypes ****************************************************/
void objects_abort (void);
#endif /* __abort_h_OBJECTS_INCLUDE */

View file

@ -1,82 +0,0 @@
/* Modular memory management. Better living through chemicals.
* Copyright (C) 1994, 1995, 1996 Free Software Foundation, Inc.
*
* Author: Albin L. Jones <Albin.L.Jones@Dartmouth.EDU>
* Created: Thu Oct 13 23:46:02 EDT 1994
* Updated: Sat Feb 10 15:47:25 EST 1996
* Serial: 96.02.10.01
*
* This file is part of the GNU Objective C Class Library.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the Free
* Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*
*/
#ifndef __allocs_h_OBJECTS_INCLUDE
#define __allocs_h_OBJECTS_INCLUDE 1
/**** Included Headers *******************************************************/
#include <stdlib.h>
/**** Type, Constant, and Macro Definitions **********************************/
typedef void *(*objects_malloc_func_t) (size_t, const void *);
typedef void *(*objects_calloc_func_t) (size_t, size_t, const void *);
typedef void *(*objects_realloc_func_t) (void *, size_t, const void *);
typedef void (*objects_free_func_t) (void *, const void *);
typedef struct _objects_allocs objects_allocs_t;
struct _objects_allocs
{
objects_malloc_func_t malloc;
objects_calloc_func_t calloc;
objects_realloc_func_t realloc;
objects_free_func_t free;
const void *user_data;
};
/* Shorthand macros. */
#define OBJECTS_MALLOC(S) objects_malloc(objects_standard_allocs(), (S))
#define OBJECTS_CALLOC(N, S) objects_calloc(objects_standard_allocs(), (N), (S))
#define OBJECTS_REALLOC(P, S) objects_realloc(objects_standard_allocs(), (P), (S))
#define OBJECTS_FREE(P) objects_free(objects_standard_allocs(), (P))
/* Change these if you need different default allocs. */
extern objects_allocs_t __objects_allocs_standard;
/**** Function Prototypes ****************************************************/
/* Returns `__objects_allocs_standard', defined above. */
objects_allocs_t
objects_allocs_standard (void);
void *
objects_malloc (objects_allocs_t allocs, size_t s);
void *
objects_calloc (objects_allocs_t allocs, size_t n, size_t s);
void *
objects_realloc (objects_allocs_t allocs, const void *p, size_t s);
void
objects_free (objects_allocs_t allocs, const void *p);
size_t
objects_next_power_of_two (size_t start);
#endif /* __allocs_h_OBJECTS_INCLUDE */

View file

@ -1,10 +1,10 @@
/* A sparse array for use with Libobjects.
/* A sparse array structure.
* Copyright (C) 1994, 1995, 1996 Free Software Foundation, Inc.
*
* Author: Albin L. Jones <Albin.L.Jones@Dartmouth.EDU>
* Created: Thu Mar 2 02:30:02 EST 1994
* Updated: Sat Feb 10 15:38:58 EST 1996
* Serial: 96.02.10.01
* Updated: Tue Mar 12 02:42:54 EST 1996
* Serial: 96.03.12.13
*
* This file is part of the GNU Objective C Class Library.
*
@ -20,9 +20,7 @@
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the Free
* Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*
*/
* Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
#ifndef __array_h_OBJECTS_INCLUDE
#define __array_h_OBJECTS_INCLUDE 1
@ -30,7 +28,7 @@
/**** Included Headers *******************************************************/
#include <stdlib.h>
#include <objects/allocs.h>
#include <Foundation/NSZone.h>
#include <objects/callbacks.h>
#include <objects/hash.h>
@ -42,157 +40,209 @@ typedef objects_array_bucket_t *objects_array_slot_t;
typedef struct _objects_array_enumerator objects_array_enumerator_t;
struct _objects_array_bucket
{
/* The bucket's real (or external) index */
size_t index;
{
/* The bucket's real (or external) index */
size_t index;
/* The bucket's cargo */
const void *element;
};
/* The bucket's cargo */
const void *element;
};
struct _objects_array
{
/* Identifying information. */
int magic;
size_t number;
const char *name;
const void *extra;
objects_callbacks_t extra_callbacks;
objects_allocs_t allocs;
{
/* Identifying information. */
int magic_number;
size_t serial_number;
NSZone *zone;
NSString *name;
const void *extra;
objects_callbacks_t extra_callbacks;
/* Callbacks for the items in the array. */
objects_callbacks_t callbacks;
/* Callbacks for the items in the array. */
objects_callbacks_t callbacks;
/* Internal counters */
size_t slot_count;
size_t element_count;
/* Internal counters */
size_t slot_count;
size_t element_count;
/* Databanks */
objects_array_slot_t *slots;
objects_array_slot_t *sorted_slots;
};
/* Databanks */
objects_array_slot_t *slots;
objects_array_slot_t *sorted_slots;
};
struct _objects_array_enumerator
{
objects_array_t * array;
size_t index;
int is_sorted;
int is_ascending;
};
{
objects_array_t *array;
size_t index;
int is_sorted;
int is_ascending;
};
/**** Function Prototypes ****************************************************/
/** Basics **/
#include <objects/array-basics.h>
#include <objects/array-callbacks.h>
#include <objects/array-bas.h>
#include <objects/array-cbs.h>
/** Creating **/
objects_array_t * objects_array_alloc (void);
objects_array_t *
objects_array_alloc(void);
objects_array_t * objects_array_alloc_with_allocs (objects_allocs_t allocs);
objects_array_t *
objects_array_alloc_with_zone(NSZone *zone);
objects_array_t * objects_array (void);
objects_array_t *
objects_array(void);
objects_array_t * objects_array_with_allocs (objects_allocs_t allocs);
objects_array_t *
objects_array_with_zone(NSZone *zone);
objects_array_t * objects_array_with_allocs_with_callbacks (objects_allocs_t allocs, objects_callbacks_t callbacks);
objects_array_t *
objects_array_with_zone_with_callbacks(NSZone *zone,
objects_callbacks_t callbacks);
objects_array_t * objects_array_with_callbacks (objects_callbacks_t callbacks);
objects_array_t *
objects_array_with_callbacks(objects_callbacks_t callbacks);
objects_array_t * objects_array_of_char_p (void);
objects_array_t *
objects_array_of_char_p(void);
objects_array_t * objects_array_of_void_p (void);
objects_array_t *
objects_array_of_non_owned_void_p(void);
objects_array_t * objects_array_of_owned_void_p (void);
objects_array_t *
objects_array_of_owned_void_p(void);
objects_array_t * objects_array_of_int (void);
objects_array_t *
objects_array_of_int(void);
objects_array_t * objects_array_of_id (void);
objects_array_t *
objects_array_of_id(void);
/** Initializing **/
objects_array_t * objects_array_init (objects_array_t * array);
objects_array_t *
objects_array_init(objects_array_t *array);
objects_array_t * objects_array_init_with_callbacks (objects_array_t * array, objects_callbacks_t callbacks);
objects_array_t *
objects_array_init_with_callbacks(objects_array_t *array,
objects_callbacks_t callbacks);
objects_array_t * objects_array_init_with_array (objects_array_t * array, objects_array_t * other_array);
objects_array_t *
objects_array_init_with_array(objects_array_t *array,
objects_array_t *other_array);
/** Copying **/
objects_array_t * objects_array_copy (objects_array_t * array);
objects_array_t *
objects_array_copy(objects_array_t *array);
objects_array_t * objects_array_copy_with_allocs (objects_array_t * array, objects_allocs_t allocs);
objects_array_t *
objects_array_copy_with_zone(objects_array_t *array, NSZone *zone);
/** Destroying **/
void objects_array_dealloc (objects_array_t * array);
void
objects_array_dealloc(objects_array_t *array);
/** Comparing **/
int objects_array_is_equal_to_array (objects_array_t * array, objects_array_t * other_array);
int
objects_array_is_equal_to_array(objects_array_t *array,
objects_array_t *other_array);
/** Adding **/
const void *objects_array_at_index_put_element (objects_array_t * array, size_t index, const void *element);
const void *
objects_array_at_index_put_element(objects_array_t *array,
size_t index,
const void *element);
/** Replacing **/
/** Removing **/
void objects_array_remove_element_at_index (objects_array_t * array, size_t index);
void
objects_array_remove_element_at_index(objects_array_t *array, size_t index);
void objects_array_remove_element (objects_array_t * array, const void *element);
void
objects_array_remove_element(objects_array_t *array, const void *element);
void objects_array_remove_element_known_present (objects_array_t * array, const void *element);
void
objects_array_remove_element_known_present(objects_array_t *array,
const void *element);
/** Emptying **/
void objects_array_empty (objects_array_t * array);
void
objects_array_empty(objects_array_t *array);
/** Searching **/
int objects_array_contains_element (objects_array_t * array, const void *element);
int
objects_array_contains_element(objects_array_t *array, const void *element);
const void *objects_array_element (objects_array_t * array, const void *element);
const void *
objects_array_element(objects_array_t *array, const void *element);
size_t objects_array_index_of_element (objects_array_t * array, const void *element);
size_t
objects_array_index_of_element(objects_array_t *array, const void *element);
const void *objects_array_element_at_index (objects_array_t * array, size_t index);
const void *
objects_array_element_at_index(objects_array_t *array, size_t index);
const void **objects_array_all_elements (objects_array_t * array);
const void **
objects_array_all_elements(objects_array_t *array);
const void **objects_array_all_elements_ascending (objects_array_t * array);
const void **
objects_array_all_elements_ascending(objects_array_t *array);
const void **objects_array_all_element_descending (objects_array_t * array);
const void **
objects_array_all_element_descending(objects_array_t *array);
/** Enumerating **/
objects_array_enumerator_t objects_array_enumerator (objects_array_t * array);
objects_array_enumerator_t
objects_array_enumerator(objects_array_t *array);
objects_array_enumerator_t objects_array_ascending_enumerator (objects_array_t * array);
objects_array_enumerator_t
objects_array_ascending_enumerator(objects_array_t *array);
objects_array_enumerator_t objects_array_descending_enumerator (objects_array_t * array);
objects_array_enumerator_t
objects_array_descending_enumerator(objects_array_t *array);
int objects_array_enumerator_next_index_and_element (objects_array_enumerator_t *enumerator, size_t *index, const void **element);
int
objects_array_enumerator_next_index_and_element(objects_array_enumerator_t *enumerator,
size_t *index,
const void **element);
int objects_array_enumerator_next_element (objects_array_enumerator_t *enumerator, const void **element);
int
objects_array_enumerator_next_element(objects_array_enumerator_t *enumerator,
const void **element);
int objects_array_enumerator_next_index (objects_array_enumerator_t *enumerator, size_t *element);
int
objects_array_enumerator_next_index(objects_array_enumerator_t *enumerator,
size_t *element);
/** Statistics **/
int objects_array_is_empty (objects_array_t * array);
int
objects_array_is_empty(objects_array_t *array);
size_t objects_array_count (objects_array_t * array);
size_t
objects_array_count(objects_array_t *array);
size_t objects_array_capacity (objects_array_t * array);
size_t
objects_array_capacity(objects_array_t *array);
int objects_array_check (objects_array_t * array);
int
objects_array_check(objects_array_t *array);
/** Miscellaneous **/
objects_hash_t *objects_hash_init_from_array (objects_hash_t *hash, objects_array_t *array);
objects_hash_t *
objects_hash_init_from_array(objects_hash_t *hash, objects_array_t *array);
#endif /* __array_h_OBJECTS_INCLUDE */

View file

@ -1,59 +0,0 @@
/* Macros for bit-wise operations.
* Copyright (C) 1996 Free Software Foundation, Inc.
*
* Author: Albin L. Jones <Albin.L.Jones@Dartmouth.EDU>
* Created: Sat Feb 10 21:17:10 EST 1996
* Updated: Sat Feb 10 21:17:10 EST 1996
* Serial: 96.02.10.01
*
* This file is part of the GNU Objective C Class Library.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the Free
* Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*
*/
/**** Included Headers *******************************************************/
#include <objects/callbacks.h>
/**** Type, Constant, and Macro Definitions **********************************/
/**** Function Implementations ***********************************************/
#ifndef __bits_h_OBJECTS_INCLUDE
#define __bits_h_OBJECTS_INCLUDE 1
/**** Included Headers *******************************************************/
/**** Type, Constant, and Macro Definitions **********************************/
/** Bit operations **/
/* Set the Nth bit of V to one. */
#define OBJECTS_BIT_POKE(V,N) ((V) |= (1 << (N)))
/* Set the Nth bit of V to zero. */
#define OBJECTS_BIT_NOCK(V,N) ((V) &= ~(1 << (N)))
/* Toggle the Nth bit of V. */
#define OBJECTS_BIT_PLUK(V,N) ((V) ^= (1 << (N)))
/* Grab the Nth bit of V. */
#define OBJECTS_BIT_PEEK(V,N) ((V) & (1 << (N)))
/**** Function Prototypes ****************************************************/
#endif /* __bits_h_OBJECTS_INCLUDE */

View file

@ -20,9 +20,7 @@
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the Free
* Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*
*/
* Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
#ifndef __data_h_OBJECTS_INCLUDE
#define __data_h_OBJECTS_INCLUDE 1
@ -74,7 +72,7 @@ struct _objects_data
/** Basics **/
#include <objects/data-basics.h>
#include <objects/data-bas.h>
/** Hashing **/

View file

@ -1,10 +1,10 @@
/* A hash table for use with Libobjects.
/* A hash table.
* Copyright (C) 1993, 1994, 1995, 1996 Free Software Foundation, Inc.
*
* Author: Albin L. Jones <Albin.L.Jones@Dartmouth.EDU>
* Created: ??? ??? ?? ??:??:?? ??? 1993
* Updated: Sat Feb 10 15:35:37 EST 1996
* Serial: 96.02.10.01
* Updated: Tue Mar 19 00:25:34 EST 1996
* Serial: 96.03.19.05
*
* This file is part of the GNU Objective C Class Library.
*
@ -20,208 +20,374 @@
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the Free
* Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*
*/
* Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
#ifndef __hash_h_OBJECTS_INCLUDE
#define __hash_h_OBJECTS_INCLUDE 1
/**** Included Headers *******************************************************/
#include <objects/allocs.h>
#include <Foundation/NSZone.h>
#include <Foundation/NSString.h>
#include <objects/callbacks.h>
/**** Type, Constant, and Macro Definitions **********************************/
/* Need these up here because of their interdependence. */
typedef struct _objects_hash objects_hash_t;
typedef struct _objects_hash_bucket objects_hash_bucket_t;
typedef struct _objects_hash_node objects_hash_node_t;
typedef struct _objects_hash_enumerator objects_hash_enumerator_t;
typedef struct _objects_hash_node objects_hash_node_t;
typedef struct _objects_hash_bucket objects_hash_bucket_t;
/* Private type for elemental holding. */
struct _objects_hash_node
{
objects_hash_t *hash;
objects_hash_bucket_t *bucket;
{
/* The hash table with which the node is associated. */
objects_hash_t *hash;
objects_hash_node_t *next_in_bucket;
objects_hash_node_t *prev_in_bucket;
objects_hash_node_t *next_in_hash;
objects_hash_node_t *prev_in_hash;
/* The bucket in HASH in which the node sits. */
objects_hash_bucket_t *bucket;
const void *element;
};
/* These hold the BUCKET linked list together. */
objects_hash_node_t *next_in_bucket;
objects_hash_node_t *prev_in_bucket;
/* For enumerating over the whole hash table. These make
* enumerating much quicker. They also make it safer. */
objects_hash_node_t *next_in_hash;
objects_hash_node_t *prev_in_hash;
/* What the node is holding for us. Its raison d'etre. */
const void *element;
};
/* Private type for holding chains of nodes. */
struct _objects_hash_bucket
{
size_t node_count;
size_t element_count;
{
/* The number of nodes in this bucket. For internal consistency checks. */
size_t node_count;
objects_hash_node_t *first_node;
};
/* The number of elements in this bucket. (This had *better* be
* the same as NODE_COUNT, or something's wrong.) */
size_t element_count;
/* The head of this bucket's linked list of nodes. */
objects_hash_node_t *first_node;
};
/* The hash table type. */
struct _objects_hash
{
int magic;
size_t number;
const char *name;
const void *extra;
objects_callbacks_t extra_callbacks;
objects_allocs_t allocs;
{
/* All structures have these...
* And all structures have them in the same order. */
int magic_number;
size_t serial_number;
NSZone *zone;
NSString *name;
const void *extra;
objects_callbacks_t extra_callbacks;
/* Callbacks for the items in the hash. */
objects_callbacks_t callbacks;
/* Callbacks for the elements of the hash. */
objects_callbacks_t callbacks;
/* Internal hash counters. */
size_t bucket_count; /* How many types of items? */
size_t node_count; /* How many items? */
size_t element_count; /* How many elements? */
/* Internal counters. Mainly for consistency's sake. */
size_t bucket_count; /* How many types of items? */
size_t node_count; /* How many items? */
size_t element_count; /* How many elements? */
/* Places to start looking for elements. */
objects_hash_bucket_t *buckets;
objects_hash_node_t *first_node;
};
/* Places to start looking for elements. */
objects_hash_bucket_t *buckets; /* Organized as a hash. */
objects_hash_node_t *first_node; /* Organized as a linked list.
* (For enumerating...) */
};
/* Type for enumerating the elements of a hash table. */
struct _objects_hash_enumerator
{
objects_hash_t *hash;
objects_hash_node_t *node;
};
{
objects_hash_t *hash; /* To which hash do I belong? */
objects_hash_node_t *node; /* Which node is next? */
};
/**** Function Prototypes ****************************************************/
/** Basics **/
/** Basics... **/
#include <objects/hash-basics.h>
#include <objects/hash-callbacks.h>
/* All the structures (hashes, maps, lists, and arrays) have
* the same basic ideas behind them. */
/** Hashing **/
#include <objects/hash-bas.h>
#include <objects/hash-cbs.h>
size_t objects_hash_hash (objects_hash_t * hash);
/** Callbacks... **/
/** Creating **/
/* Returns a collection of callbacks for use with hash tables. */
objects_callbacks_t
objects_callbacks_for_hash(void);
objects_hash_t * objects_hash_alloc (void);
/** Creating... **/
objects_hash_t * objects_hash_alloc_with_allocs (objects_allocs_t alloc);
/* Allocate a hash table in the default zone. */
objects_hash_t *
objects_hash_alloc(void);
objects_hash_t * objects_hash_with_callbacks (objects_callbacks_t callbacks);
/* Allocate a hash table in the memory block ZONE. */
objects_hash_t *
objects_hash_alloc_with_zone(NSZone *zone);
objects_hash_t * objects_hash_with_allocs (objects_allocs_t allocs);
/* Create an empty hash table in the memory block ZONE. The returned
* hash table has a "reasonable" default capacity, but will need to
* be resized to suit your specific needs if more than a couple of
* dozen elements will be placed within it. */
objects_hash_t *
objects_hash_with_zone_with_callbacks(NSZone *zone,
objects_callbacks_t callbacks);
objects_hash_t * objects_hash_with_allocs_with_callbacks (objects_allocs_t allocs, objects_callbacks_t callbacks);
/* Like calling 'objects_hash_with_zone_with_callbacks(zone,
* objects_callbacks_standard())'. */
objects_hash_t *
objects_hash_with_zone(NSZone *zone);
objects_hash_t * objects_hash_of_char_p (void);
/* Like calling 'objects_hash_with_zone_with_callbacks(0, callbacks)'. */
objects_hash_t *
objects_hash_with_callbacks(objects_callbacks_t callbacks);
objects_hash_t * objects_hash_of_void_p (void);
/* These are just shortcuts for ease of use. */
objects_hash_t *objects_hash_of_char_p(void);
objects_hash_t *objects_hash_of_non_owned_void_p(void);
objects_hash_t *objects_hash_of_owned_void_p(void);
objects_hash_t *objects_hash_of_int(void);
objects_hash_t *objects_hash_of_int_p(void);
objects_hash_t *objects_hash_of_id(void);
objects_hash_t * objects_hash_of_owned_void_p (void);
/** Initializing... **/
objects_hash_t * objects_hash_of_int (void);
/* Initializes HASH with a "reasonable" capacity, with the
* callbacks obtained from 'objects_callbacks_standard()'. */
objects_hash_t *
objects_hash_init(objects_hash_t *hash);
objects_hash_t * objects_hash_of_id (void);
/* Initializes HASH with a "reasonable" capacity and
* with element callbacks CALLBACKS. */
objects_hash_t *
objects_hash_init_with_callbacks(objects_hash_t *hash,
objects_callbacks_t callbacks);
/** Initializing **/
/* Initializes HASH with the capacity, callbacks, and contents
* of OTHER_HASH. NOTE: This is (as it must be) a "shallow" copying.
* See 'objects_hash_copy_with_zone()', below. */
objects_hash_t *
objects_hash_init_with_hash(objects_hash_t *hash,
objects_hash_t *other_hash);
objects_hash_t * objects_hash_init (objects_hash_t * hash);
/** Copying... **/
objects_hash_t * objects_hash_init_with_callbacks (objects_hash_t * hash, objects_callbacks_t callbacks);
/* Creates a (shallow) copy of HASH in the memory block ZONE. WARNING:
* If the elements of HASH are pointers to mutable items, it is the
* programmer's responsibility to deepen the copy returned by this
* function call (using, for example, `objects_hash_map_elements()'). */
objects_hash_t *
objects_hash_copy_with_zone(objects_hash_t *hash, NSZone *zone);
objects_hash_t * objects_hash_init_with_hash (objects_hash_t * hash, objects_hash_t * other_hash);
/* Create a (shallow) copy of HASH in the default zone. WARNING: See the
* above function for an important caveat about copying. */
objects_hash_t *
objects_hash_copy(objects_hash_t *old_hash);
/** Copying **/
objects_hash_t * objects_hash_copy (objects_hash_t * old_hash);
objects_hash_t * objects_hash_copy_with_allocs (objects_hash_t * hash, objects_allocs_t new_allocs);
/** Mapping **/
/** Mapping... **/
/* WARNING: The mapping function FCN must be one-to-one on elements of
* HASH. I.e., for reasons of efficiency, `objects_hash_map_elements()'
* makes no provision for the possibility that FCN maps two unequal
* elements of HASH to the same (or equal) elements. The better way
* elements of HASH to the same (or "equal") elements. The better way
* to handle functions that aren't one-to-one is to create a new hash
* and transform the elements of the first to create the elements of
* the second. */
objects_hash_t *
objects_hash_map_elements (objects_hash_t * hash,
const void *(*fcn) (const void *, const void *),
const void *user_data);
* the second (by manual enumeration). */
objects_hash_t *
objects_hash_map_elements(objects_hash_t *hash,
const void *(*fcn)(const void *, const void *),
const void *user_data);
/** Destroying **/
/** Destroying... **/
void objects_hash_dealloc (objects_hash_t * hash);
/* Releases all the elements of HASH, and then frees up the space
* HASH used. HASH is no longer a (pointer to a) valid hash
* table structure after this call. */
void
objects_hash_dealloc(objects_hash_t *hash);
/** Comparing **/
/** Comparing... **/
int objects_hash_contains_hash (objects_hash_t * hash, objects_hash_t * other_hash);
/* Returns 'true' if every element of OTHER_HASH is also
* a member of HASH. Otherwise, returns 'false'. */
int
objects_hash_contains_hash(objects_hash_t *hash,
objects_hash_t *other_hash);
int objects_hash_intersects_hash (objects_hash_t * hash, objects_hash_t * other_hash);
/* Returns 'true' if some element of HASH is also
* a member of OTHER_HASH. Otherwise, returns 'false'. */
int
objects_hash_intersects_hash(objects_hash_t *hash,
objects_hash_t *other_hash);
int objects_hash_is_equal_to_hash (objects_hash_t * hash, objects_hash_t * other_hash);
/* Returns 'true' if HASH and OTHER_HASH have the same number of elements,
* HASH contains OTHER_HASH, and OTHER_HASH contains HASH. Otheraise, returns 'false'. */
int
objects_hash_is_equal_to_hash(objects_hash_t *hash,
objects_hash_t *other_hash);
/** Adding **/
/** Adding... **/
const void *objects_hash_add_element_known_absent (objects_hash_t *hash,
const void *element);
/* Adds ELEMENT to HASH. If ELEMENT is "equal" to an item already in HASH,
* then we abort. If ELEMENT is the "not an element marker" for HASH,
* then we abort. [NOTE: This abortive behaviour will be changed in a
* future revision.] */
const void *
objects_hash_add_element_known_absent(objects_hash_t *hash,
const void *element);
const void *objects_hash_add_element (objects_hash_t *hash,
const void *element);
/* Adds ELEMENT to HASH. If ELEMENT is "equal" to an item already in HASH,
* then that older item is released using the 'release()' callback function
* that was specified when HASH was created. (If ELEMENT is the "not an
* element marker" for HASH, then all bets are off, and we abort.
* [NOTE: This abortive behaviour will be changed in a future revision.]) */
const void *
objects_hash_add_element(objects_hash_t *hash, const void *element);
const void *objects_hash_add_element_if_absent (objects_hash_t *hash,
const void *element);
/* If (any item "equal" to) ELEMENT is in HASH, then that member of HASH is
* returned. Otherwise, the "not an element marker" for HASH is returned
* and ELEMENT is added to HASH. If ELEMENT is the "not an element marker"
* for HASH, then we abort. [NOTE: This abortive behaviour will be changed
* in a future revision.] */
const void *
objects_hash_add_element_if_absent(objects_hash_t *hash, const void *element);
/** Replacing **/
/** Replacing... **/
void objects_hash_replace_element (objects_hash_t *hash, const void *element);
/* If (some item "equal" to) ELEMENT is an element of HASH, then ELEMENT is
* substituted for it. The old element is released. (This is rather
* like the non-existant but perfectly reasonable function
* 'objects_hash_add_element_if_present()'.) */
void
objects_hash_replace_element(objects_hash_t *hash,
const void *element);
/** Removing **/
/** Removing... **/
void objects_hash_remove_element (objects_hash_t *hash, const void *element);
/* Removes the element (if any) of HASH which is "equal" to ELEMENT,
* according to HASH's element callbacks. It is not an error to
* remove ELEMENT from HASH, if no element of HASH is "equal" to ELEMENT. */
void
objects_hash_remove_element(objects_hash_t *hash, const void *element);
/** Emptying **/
/** Emptying... **/
void objects_hash_empty (objects_hash_t *hash);
/* Empties HASH, releasing all of its elements while retaining
* its current "capacity". */
void
objects_hash_empty(objects_hash_t *hash);
/** Searching **/
/** Searching... **/
void *objects_hash_any_element (objects_hash_t *hash);
/* Returns a "random" element of HASH, for your viewing enjoyment. */
void *
objects_hash_any_element(objects_hash_t *hash);
int objects_hash_contains_element (objects_hash_t *hash, const void *element);
/* Returns `true' if some element of HASH is "equal" to ELEMENT,
* according to HASH's element callbacks. */
int
objects_hash_contains_element(objects_hash_t *hash, const void *element);
const void *objects_hash_element (objects_hash_t *hash, const void *element);
/* Returns the element of HASH (or the appropriate `not an element
* marker' if there is none) which is "equal" to ELEMENT. */
const void *
objects_hash_element(objects_hash_t *hash, const void *element);
const void **objects_hash_all_elements (objects_hash_t *hash);
/* Returns an array with all the elements of HASH, terminated
* by HASH's "not an element marker". It is your responsibility
* to free the returned array. [NOTE: this responsibility may
* shift from your shoulders in a later revision.] */
const void **
objects_hash_all_elements(objects_hash_t *hash);
/** Enumerating **/
/** Enumerating... **/
objects_hash_enumerator_t objects_hash_enumerator (objects_hash_t *hash);
/* Returns an enumerator for HASH's elements. WARNING: DO NOT ALTER
* A HASH DURING AN ENUMERATION. DOING SO WILL PROBABLY LEAVE YOUR ENUMERATION
* IN AN INDETERMINATE STATE. If you are hell-bent on ignoring the above
* warning, please check out the source code for some more specific
* information about when and how one can get away with it. */
objects_hash_enumerator_t
objects_hash_enumerator_for_hash(objects_hash_t *hash);
int objects_hash_enumerator_next_element (objects_hash_enumerator_t *enumeratr,
const void **element);
/* Returns `false' if the enumeration is complete, `true' otherwise.
* If ELEMENT is non-zero, the next element of ENUMERATOR's hash table
* is returned by reference. */
int
objects_hash_enumerator_next_element(objects_hash_enumerator_t *enumerator,
const void **element);
/** Statistics **/
/** Statistics... **/
int objects_hash_is_empty (objects_hash_t * hash);
/* Returns `true' if HASH contains no elements. */
int
objects_hash_is_empty(objects_hash_t *hash);
size_t objects_hash_count (objects_hash_t * hash);
/* Returns the number of elements HASH is currently holding. So long as no
* additions or removals occur, you may take this number to be accurate. */
size_t
objects_hash_count(objects_hash_t *hash);
size_t objects_hash_capacity (objects_hash_t * hash);
/* Returns a number which represents (to some degree) HASH's current ability
* to hold stuff. Do not, however, rely on this for precision. Treat as
* a (reasonable) estimate. */
size_t
objects_hash_capacity(objects_hash_t *hash);
int objects_hash_check (objects_hash_t * hash);
/* Performs an internal consistency check on HASH. Useful only
* for debugging. */
int
objects_hash_check(objects_hash_t *hash);
/** Miscellaneous **/
/** Resizing... **/
size_t objects_hash_resize (objects_hash_t * hash, size_t new_capacity);
/* Resizes HASH to be ready to contain (at least) NEW_CAPACITY many elements.
* However, as far as you are concerned, it is indeterminate what exactly
* this means. After receiving and successfully processing this call,
* you are *not* guaranteed that HASH has actually set aside space for
* NEW_CAPACITY elements, for example. All that you are guaranteed is that,
* to the best of its ability, HASH will incur no loss in efficiency so long
* as it contains no more than NEW_CAPACITY elements. */
size_t
objects_hash_resize(objects_hash_t *hash, size_t new_capacity);
size_t objects_hash_rightsize (objects_hash_t * hash);
/* Shrinks (or grows) HASH to be comfortable with the number of elements
* it contains. In all likelyhood, after this call, HASH is more efficient
* in terms of its speed of search vs. use of space balance. */
size_t
objects_hash_rightsize(objects_hash_t *hash);
objects_hash_t * objects_hash_intersect_hash (objects_hash_t * hash, objects_hash_t * other_hash);
/** Describing... **/
objects_hash_t * objects_hash_minus_hash (objects_hash_t * hash, objects_hash_t * other_hash);
/* Returns a string describing (the contents of) HASH. */
NSString *
objects_hash_description(objects_hash_t *hash);
objects_hash_t * objects_hash_union_hash (objects_hash_t * hash, objects_hash_t * other_hash);
/** Set theoretic operations... **/
/* Removes from HASH all of its elements which are not also
* elements of OTHER_HASH. Returns HASH as a courtesy. */
objects_hash_t *
objects_hash_intersect_hash(objects_hash_t *hash, objects_hash_t *other_hash);
/* Removes from HASH all of its elements which are also
* elements of OTHER_HASH. Returns HASH as a courtesy. */
objects_hash_t *
objects_hash_minus_hash(objects_hash_t *hash, objects_hash_t *other_hash);
/* Adds to HASH all elements of OTHER_HASH which are not
* already members of HASH. Returns HASH as a courtesy. */
objects_hash_t *
objects_hash_union_hash(objects_hash_t *hash, objects_hash_t *other_hash);
#endif /* __hash_h_OBJECTS_INCLUDE */

View file

@ -1,10 +1,10 @@
/* A list for use with Libobjects.
/* A list structure.
* Copyright (C) 1995, 1996 Free Software Foundation, Inc.
*
* Author: Albin L. Jones <Albin.L.Jones@Dartmouth.EDU>
* Created: Tue Sep 5 17:25:59 EDT 1995
* Updated: Sat Feb 10 15:37:41 EST 1996
* Serial: 96.02.10.01
* Updated: Sun Mar 10 23:24:49 EST 1996
* Serial: 96.03.10.02
*
* This file is part of the GNU Objective C Class Library.
*
@ -20,16 +20,14 @@
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the Free
* Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*
*/
* Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
#ifndef __list_h_OBJECTS_INCLUDE
#define __list_h_OBJECTS_INCLUDE 1
/**** Included Headers *******************************************************/
#include <objects/allocs.h>
#include <Foundation/NSZone.h>
#include <objects/callbacks.h>
#include <objects/hash.h>
#include <objects/array.h>
@ -41,212 +39,308 @@ typedef struct _objects_list_node objects_list_node_t;
typedef struct _objects_list_enumerator objects_list_enumerator_t;
struct _objects_list_node
{
objects_list_t * list;
{
objects_list_t *list;
objects_list_node_t *next_in_list;
objects_list_node_t *prev_in_list;
objects_list_node_t *next_in_list;
objects_list_node_t *prev_in_list;
const void *element;
};
const void *element;
};
struct _objects_list
{
/* Container identifiers */
int magic;
size_t number;
char *name;
const void *extra;
objects_callbacks_t extra_callbacks;
objects_allocs_t allocs;
{
/* Container identifiers */
int magic_number;
size_t serial_number;
NSZone *zone;
NSString *name;
const void *extra;
objects_callbacks_t extra_callbacks;
/* Element callbacks */
objects_callbacks_t callbacks;
/* Element callbacks */
objects_callbacks_t callbacks;
/* Internal counters */
size_t node_count;
size_t element_count;
/* Internal counters */
size_t node_count;
size_t element_count;
/* Databanks */
objects_list_node_t *first_node;
objects_list_node_t *last_node;
};
/* Databanks */
objects_list_node_t *first_node;
objects_list_node_t *last_node;
};
struct _objects_list_enumerator
{
objects_list_t *list;
objects_list_node_t *node;
size_t forward;
};
{
objects_list_t *list;
objects_list_node_t *node;
size_t forward;
};
/**** Function Prototypes ****************************************************/
/** Basics **/
#include <objects/list-basics.h>
#include <objects/list-callbacks.h>
#include <objects/list-bas.h>
#include <objects/list-cbs.h>
/** Creating **/
objects_list_t * objects_list_alloc (void);
objects_list_t *
objects_list_alloc(void);
objects_list_t * objects_list_alloc_with_allocs (objects_allocs_t allocs);
objects_list_t *
objects_list_alloc_with_zone(NSZone *zone);
objects_list_t * objects_list_with_allocs (objects_allocs_t allocs);
objects_list_t *
objects_list_with_zone(NSZone *zone);
objects_list_t * objects_list_with_callbacks (objects_callbacks_t callbacks);
objects_list_t *
objects_list_with_callbacks(objects_callbacks_t callbacks);
objects_list_t * objects_list_with_allocs_with_callbacks (objects_allocs_t allocs, objects_callbacks_t callbacks);
objects_list_t *
objects_list_with_zone_with_callbacks(NSZone *zone,
objects_callbacks_t callbacks);
objects_list_t * objects_list_of_char_p (void);
objects_list_t *
objects_list_of_char_p(void);
objects_list_t * objects_list_of_void_p (void);
objects_list_t *
objects_list_of_non_owned_void_p(void);
objects_list_t * objects_list_of_owned_void_p (void);
objects_list_t *
objects_list_of_owned_void_p(void);
objects_list_t * objects_list_of_int (void);
objects_list_t *
objects_list_of_int(void);
objects_list_t * objects_list_of_int_p (void);
objects_list_t *
objects_list_of_int_p(void);
objects_list_t * objects_list_of_id (void);
objects_list_t *
objects_list_of_id(void);
/** Initializing **/
objects_list_t * objects_list_init (objects_list_t * list);
objects_list_t *
objects_list_init(objects_list_t *list);
objects_list_t * objects_list_init_with_callbacks (objects_list_t * list, objects_callbacks_t callbacks);
objects_list_t *
objects_list_init_with_callbacks(objects_list_t *list,
objects_callbacks_t callbacks);
/** Copying **/
objects_list_t * objects_list_copy (objects_list_t * old_list);
objects_list_t *
objects_list_copy(objects_list_t *old_list);
objects_list_t * objects_list_copy_with_allocs (objects_list_t * old_list, objects_allocs_t allocs);
objects_list_t *
objects_list_copy_with_zone(objects_list_t *old_list,
NSZone *zone);
/** Destroying **/
void objects_list_dealloc (objects_list_t * list);
void
objects_list_dealloc(objects_list_t *list);
/** Comparing **/
int objects_list_is_equal_to_list (objects_list_t * list, objects_list_t * other_list);
int
objects_list_is_equal_to_list(objects_list_t *list,
objects_list_t *other_list);
/** Concatenating **/
objects_list_t * objects_list_append_list (objects_list_t * base_list, objects_list_t * suffix_list);
objects_list_t *
objects_list_append_list(objects_list_t *base_list,
objects_list_t *suffix_list);
objects_list_t * objects_list_prepend_list (objects_list_t * base_list, objects_list_t * prefix_list);
objects_list_t *
objects_list_prepend_list(objects_list_t *base_list,
objects_list_t *prefix_list);
objects_list_t * objects_list_at_index_insert_list (objects_list_t * base_list, long int n, objects_list_t * infix_list);
objects_list_t *
objects_list_at_index_insert_list(objects_list_t *base_list,
long int n,
objects_list_t *infix_list);
/** Permuting **/
objects_list_t * objects_list_roll_to_nth_element (objects_list_t * list, long int n);
objects_list_t *
objects_list_roll_to_nth_element(objects_list_t *list, long int n);
objects_list_t * objects_list_roll_to_element (objects_list_t * list, const void *element);
objects_list_t *
objects_list_roll_to_element(objects_list_t *list, const void *element);
objects_list_t * objects_list_roll_to_nth_occurrance_of_element (objects_list_t * list, long int n, const void *element);
objects_list_t *
objects_list_roll_to_nth_occurrance_of_element(objects_list_t *list,
long int n,
const void *element);
objects_list_t * objects_list_invert (objects_list_t * list);
objects_list_t *
objects_list_invert(objects_list_t *list);
objects_list_t * objects_list_swap_elements_at_indices (objects_list_t * list, long int m, long int n);
objects_list_t *
objects_list_swap_elements_at_indices(objects_list_t *list,
long int m,
long int n);
/** Adding **/
const void *objects_list_append_element (objects_list_t * list, const void *element);
const void *
objects_list_append_element(objects_list_t *list, const void *element);
const void *objects_list_append_element_if_absent (objects_list_t * list, const void *element);
const void *
objects_list_append_element_if_absent(objects_list_t *list,
const void *element);
const void *objects_list_prepend_element (objects_list_t * list, const void *element);
const void *
objects_list_prepend_element(objects_list_t *list, const void *element);
const void *objects_list_prepend_element_if_absent (objects_list_t * list, const void *element);
const void *
objects_list_prepend_element_if_absent(objects_list_t *list,
const void *element);
const void *objects_list_at_index_insert_element (objects_list_t * list, long int n, const void *element);
const void *
objects_list_at_index_insert_element(objects_list_t *list,
long int n,
const void *element);
const void *objects_list_at_index_insert_element_if_absent (objects_list_t * list, long int n, const void *element);
const void *
objects_list_at_index_insert_element_if_absent(objects_list_t *list,
long int n,
const void *element);
const void *objects_list_queue_push_element (objects_list_t * list, const void *element);
const void *
objects_list_queue_push_element(objects_list_t *list, const void *element);
const void *objects_list_stack_push_element (objects_list_t * list, const void *element);
const void *
objects_list_stack_push_element(objects_list_t *list, const void *element);
/** Replacing **/
void objects_list_replace_nth_occurrance_of_element (objects_list_t * list, long int n, const void *old_element, const void *new_element);
void
objects_list_replace_nth_occurrance_of_element(objects_list_t *list,
long int n,
const void *old_element,
const void *new_element);
void objects_list_replace_element (objects_list_t * list, const void *old_element, const void *new_element);
void
objects_list_replace_element(objects_list_t *list,
const void *old_element,
const void *new_element);
void objects_list_replace_nth_element (objects_list_t * list, long int n, const void *new_element);
void
objects_list_replace_nth_element(objects_list_t *list,
long int n,
const void *new_element);
void objects_list_replace_first_element (objects_list_t * list, const void *new_element);
void
objects_list_replace_first_element(objects_list_t *list,
const void *new_element);
void objects_list_replace_last_element (objects_list_t * list, const void *new_element);
void
objects_list_replace_last_element(objects_list_t *list,
const void *new_element);
/** Removing **/
void objects_list_remove_nth_occurrence_of_element (objects_list_t * list, long int n, const void *element);
void
objects_list_remove_nth_occurrence_of_element(objects_list_t *list,
long int n,
const void *element);
void objects_list_remove_element (objects_list_t * list, const void *element);
void
objects_list_remove_element(objects_list_t *list, const void *element);
void objects_list_remove_nth_element (objects_list_t * list, long int n);
void
objects_list_remove_nth_element(objects_list_t *list, long int n);
void objects_list_remove_first_element (objects_list_t * list);
void
objects_list_remove_first_element(objects_list_t *list);
void objects_list_remove_last_element (objects_list_t * list);
void
objects_list_remove_last_element(objects_list_t *list);
void objects_list_queue_pop_element (objects_list_t * list);
void
objects_list_queue_pop_element(objects_list_t *list);
void objects_list_queue_pop_nth_element (objects_list_t * list, long int n);
void
objects_list_queue_pop_nth_element(objects_list_t *list, long int n);
void objects_list_stack_pop_element (objects_list_t * list);
void
objects_list_stack_pop_element(objects_list_t *list);
void objects_list_stack_pop_nth_element (objects_list_t * list, long int n);
void
objects_list_stack_pop_nth_element(objects_list_t *list, long int n);
/** Emptying **/
void objects_list_empty (objects_list_t * list);
void
objects_list_empty(objects_list_t *list);
/** Searching **/
int objects_list_contains_element (objects_list_t * list, const void *element);
int
objects_list_contains_element(objects_list_t *list, const void *element);
const void *objects_list_element (objects_list_t * list, const void *element);
const void *
objects_list_element(objects_list_t *list, const void *element);
const void *objects_list_nth_element (objects_list_t * list, long int n);
const void *
objects_list_nth_element(objects_list_t *list, long int n);
const void *objects_list_first_element (objects_list_t * list);
const void *
objects_list_first_element(objects_list_t *list);
const void *objects_list_last_element (objects_list_t * list);
const void *
objects_list_last_element(objects_list_t *list);
const void **objects_list_all_elements (objects_list_t * list);
const void **
objects_list_all_elements(objects_list_t *list);
/** Enumerating **/
objects_list_enumerator_t objects_list_enumerator (objects_list_t * list);
objects_list_enumerator_t
objects_list_enumerator(objects_list_t *list);
objects_list_enumerator_t objects_list_forward_enumerator (objects_list_t * list);
objects_list_enumerator_t
objects_list_forward_enumerator(objects_list_t *list);
objects_list_enumerator_t objects_list_reverse_enumerator (objects_list_t * list);
objects_list_enumerator_t
objects_list_reverse_enumerator(objects_list_t *list);
int objects_list_enumerator_next_element (objects_list_enumerator_t *enumerator, const void **element);
int
objects_list_enumerator_next_element(objects_list_enumerator_t *enumerator,
const void **element);
/** Mapping **/
/* NO WARNING: The mapping function FCN need not be one-to-one on the
* elements of LIST. In fact, FCN may do whatever it likes. */
objects_list_t * objects_list_map_elements (objects_list_t * list, const void *(*fcn) (const void *, const void *), const void *user_data);
objects_list_t *
objects_list_map_elements(objects_list_t *list,
const void *(*fcn)(const void *, void *),
void *user_data);
/** Statistics **/
int objects_list_is_empty (objects_list_t * list);
int
objects_list_is_empty(objects_list_t *list);
size_t objects_list_count (objects_list_t * list);
size_t
objects_list_count(objects_list_t *list);
size_t objects_list_capacity (objects_list_t * list);
size_t
objects_list_capacity(objects_list_t *list);
int objects_list_check (objects_list_t * list);
int
objects_list_check(objects_list_t *list);
/** Miscellaneous **/
objects_hash_t *objects_hash_init_from_list (objects_hash_t *hash, objects_list_t * list);
objects_hash_t *
objects_hash_init_from_list(objects_hash_t *hash, objects_list_t *list);
#endif /* __list_h_OBJECTS_INCLUDE */

View file

@ -1,56 +0,0 @@
/* Magic numbers for identifying Libobjects structures.
* Copyright (C) 1994, 1995, 1996 Free Software Foundation, Inc.
*
* Author: Albin L. Jones <Albin.L.Jones@Dartmouth.EDU>
* Created: Thu Mar 2 02:10:10 EST 1994
* Updated: Sat Feb 10 15:42:11 EST 1996
* Serial: 96.02.10.01
*
* This file is part of the GNU Objective C Class Library.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the Free
* Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*
*/
#ifndef __magic_h_OBJECTS_INCLUDE
#define __magic_h_OBJECTS_INCLUDE 1
/**** Included Headers *******************************************************/
/**** Type, Constant, and Macro Definitions **********************************/
/** Magic numbers **/
#define OBJECTS_MAGIC_ARRAY 0xfa138008 /* Thu Mar 2 02:28:50 EST 1994 */
#define OBJECTS_MAGIC_DATA 0xfa131971 /* Fri Nov 24 21:46:14 EST 1995 */
#define OBJECTS_MAGIC_HASH 0xfa133ee5 /* ??? ??? ?? ??:??:?? ??? 1993 */
#define OBJECTS_MAGIC_HEAP 0xfa13beef /* Tue Sep 5 17:21:34 EDT 1995 */
#define OBJECTS_MAGIC_LIST 0xfa13600d /* Tue Sep 5 17:23:50 EDT 1995 */
#define OBJECTS_MAGIC_MAP 0xfa13abba /* ??? ??? ?? ??:??:?? ??? 1993 */
/* WARNING: Don't use these. They are not guaranteed to remain in future
* editions of this file. They are here only as a cheap fix for an
* annoying little problem. */
/* FIXME: Get rid of these. See `x-basics.[ch].in'
* and `x-callbacks.[ch].in'. */
#define _OBJECTS_MAGIC_array OBJECTS_MAGIC_ARRAY
#define _OBJECTS_MAGIC_data OBJECTS_MAGIC_DATA
#define _OBJECTS_MAGIC_hash OBJECTS_MAGIC_HASH
#define _OBJECTS_MAGIC_heap OBJECTS_MAGIC_HEAP
#define _OBJECTS_MAGIC_list OBJECTS_MAGIC_LIST
#define _OBJECTS_MAGIC_map OBJECTS_MAGIC_MAP
#endif /* __magic_h_OBJECTS_INCLUDE */

View file

@ -1,10 +1,10 @@
/* A map table for use with Libobjects.
/* A map table.
* Copyright (C) 1993, 1994, 1995, 1996 Free Software Foundation, Inc.
*
* Author: Albin L. Jones <Albin.L.Jones@Dartmouth.EDU>
* Created: ??? ??? ?? ??:??:?? ??? 1993
* Updated: Sat Feb 10 13:36:59 EST 1996
* Serial: 96.02.10.01
* Updated: Thu Mar 21 00:05:43 EST 1996
* Serial: 96.03.20.04
*
* This file is part of the GNU Objective C Class Library.
*
@ -20,21 +20,20 @@
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the Free
* Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*
*/
* Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
#ifndef __map_h_OBJECTS_INCLUDE
#define __map_h_OBJECTS_INCLUDE 1
/**** Included Headers *******************************************************/
#include <objects/allocs.h>
#include <Foundation/NSZone.h>
#include <objects/callbacks.h>
#include <objects/hash.h>
/**** Type, Constant, and Macro Definitions **********************************/
/* Need these up here because of their interdependence. */
typedef struct _objects_map objects_map_t;
typedef struct _objects_map_bucket objects_map_bucket_t;
typedef struct _objects_map_node objects_map_node_t;
@ -42,40 +41,56 @@ typedef struct _objects_map_enumerator objects_map_enumerator_t;
/* Important structures... */
/* Private type for elemental holding. */
struct _objects_map_node
{
const void *key;
const void *value;
objects_map_bucket_t *bucket;
/* The map table with which the node is associated. */
objects_map_t *map;
/* The bucket in MAP in which the node sits. */
objects_map_bucket_t *bucket;
/* These hold the BUCKET linked list together. */
objects_map_node_t *next_in_bucket;
objects_map_node_t *prev_in_bucket;
/* For enumerating over the whole map table. These make
* enumerating much quicker. They also make it safer. */
objects_map_node_t *next_in_map;
objects_map_node_t *prev_in_map;
const void *key;
const void *value;
};
/* Private type for holding chains of nodes. */
struct _objects_map_bucket
{
/* The number of nodes in this bucket. For internal consistency checks. */
size_t node_count;
/* The number of elements in this bucket. (This had *better* be
* the same as NODE_COUNT, or something's wrong.) */
size_t element_count;
/* The head of this bucket's linked list of nodes. */
objects_map_node_t *first_node;
};
/* The map table type. */
struct _objects_map
{
/* Container identifiers */
int magic;
size_t number;
char *name;
/* All structures have these...
* And all structures have them in the same order. */
int magic_number;
size_t serial_number;
NSZone *zone;
NSString *name;
const void *extra;
objects_callbacks_t extra_callbacks;
objects_allocs_t allocs;
objects_callbacks_t key_callbacks;
/* Management information */
/* For keys...And Values. */
objects_callbacks_t key_callbacks;
objects_callbacks_t value_callbacks;
/* Internal counters */
@ -83,248 +98,332 @@ struct _objects_map
size_t node_count;
size_t element_count;
/* Databanks */
objects_map_bucket_t *buckets;
objects_map_node_t *first_node;
/* Places to start looking for elements. */
objects_map_bucket_t *buckets; /* Organized as a hash. */
objects_map_node_t *first_node; /* Organized as a linked list.
* (For enumerating...) */
};
/* Type for enumerating the elements of a map table. */
struct _objects_map_enumerator
{
objects_map_t *map;
objects_map_node_t *node;
objects_map_t *map; /* To which hash do I belong? */
objects_map_node_t *node; /* Which node is next? */
};
/**** Function Prototypes ****************************************************/
/** Basics **/
/** Basics... **/
#include <objects/map-basics.h>
#include <objects/map-callbacks.h>
/* All the structures (hashes, maps, lists, and arrays) have
* the same basic ideas behind them. */
/** Altering capacity **/
#include <objects/map-bas.h>
#include <objects/map-cbs.h>
size_t
objects_map_resize (objects_map_t * map, size_t new_capacity);
/** Callbacks... **/
size_t
objects_map_rightsize (objects_map_t * map);
/* Returns a collection of callbacks for use with hash tables. */
objects_callbacks_t
objects_callbacks_for_map(void);
/** Creating **/
/** Creating... **/
/* Allocate a hash table in the default zone. */
objects_map_t *
objects_map_alloc(void);
/* Allocate a hash table in the memory block ZONE. */
objects_map_t *
objects_map_alloc_with_zone(NSZone *zone);
/* Create an empty map table in the memory block ZONE. The returned
* hash table has a "reasonable" default capacity, but will need to
* be resized to suit your specific needs if more than a couple of
* dozen key/value pairs will be placed within it. */
objects_map_t *
objects_map_with_zone_with_callbacks(NSZone *zone,
objects_callbacks_t key_callbacks,
objects_callbacks_t value_callbacks);
/* Like calling 'objects_map_with_zone_with_callbacks(0, key_callbacks,
* value_callbacks)'. */
objects_map_t *
objects_map_with_callbacks(objects_callbacks_t key_callbacks,
objects_callbacks_t value_callbacks);
/* Like calling 'objects_map_with_zone_with_callbacks(0,
* objects_callbacks_standard(), objects_callbacks_standard())'. */
objects_map_t *
objects_map_with_zone(NSZone *zone);
/* Shortcuts... */
objects_map_t *objects_map_of_int(void);
objects_map_t *objects_map_of_int_to_char_p(void);
objects_map_t *objects_map_of_int_to_non_owned_void_p(void);
objects_map_t *objects_map_of_int_to_id(void);
objects_map_t *objects_map_of_char_p(void);
objects_map_t *objects_map_of_char_p_to_int(void);
objects_map_t *objects_map_of_char_p_to_non_owned_void_p(void);
objects_map_t *objects_map_of_char_p_to_id(void);
objects_map_t *objects_map_of_non_owned_void_p(void);
objects_map_t *objects_map_of_non_owned_void_p_to_int(void);
objects_map_t *objects_map_of_non_owned_void_p_to_char_p(void);
objects_map_t *objects_map_of_non_owned_void_p_to_id(void);
objects_map_t *objects_map_of_id(void);
/** Initializing... **/
objects_map_t *
objects_map_alloc (void);
objects_map_init(objects_map_t *map);
objects_map_t *
objects_map_alloc_with_allocs (objects_allocs_t allocs);
objects_map_init_with_callbacks(objects_map_t *map,
objects_callbacks_t key_callbacks,
objects_callbacks_t value_callbacks);
objects_map_t *
objects_map (void);
object_map_init_from_map(objects_map_t *map, objects_map_t *old_map);
objects_map_t *
objects_map_with_allocs (objects_allocs_t allocs);
objects_map_t *
objects_map_with_allocs_with_callbacks (objects_allocs_t allocs,
objects_callbacks_t key_callbacks,
objects_callbacks_t value_callbacks);
objects_map_t *
objects_map_with_callbacks (objects_callbacks_t key_callbacks,
objects_callbacks_t value_callbacks);
objects_map_t *
objects_map_of_int (void);
objects_map_t *
objects_map_of_int_to_char_p (void);
objects_map_t *
objects_map_of_int_to_void_p (void);
objects_map_t *
objects_map_of_int_to_float (void);
objects_map_t *
objects_map_of_char_p (void);
objects_map_t *
objects_map_of_char_p_to_int (void);
objects_map_t *
objects_map_of_char_p_to_void_p (void);
objects_map_t *
objects_map_of_char_p_to_float (void);
objects_map_t *
objects_map_of_void_p (void);
objects_map_t *
objects_map_of_void_p_to_int (void);
objects_map_t *
objects_map_of_void_p_to_char_p (void);
objects_map_t *
objects_map_of_void_p_to_float (void);
objects_map_t *
objects_map_of_float (void);
objects_map_t *
objects_map_of_double (void);
/** Initializing **/
objects_map_t *
objects_map_init (objects_map_t * map);
objects_map_t *
objects_map_init_with_callbacks (objects_map_t * map,
objects_callbacks_t key_callbacks,
objects_callbacks_t value_callbacks);
/** Destroying **/
/** Destroying... **/
/* Releases all the keys and values of MAP, and then
* deallocates MAP itself. */
void
objects_map_dealloc (objects_map_t * map);
objects_map_dealloc(objects_map_t *map);
/** Gathering statistics on a mapionary **/
/** Gathering statistics on a map... **/
/* Returns the number of key/value pairs in MAP. */
size_t
objects_map_pair_count (objects_map_t * map);
objects_map_count(objects_map_t *map);
/* Returns some (inexact) measure of how many key/value pairs
* MAP can comfortably hold without resizing. */
size_t
objects_map_capacity (objects_map_t * map);
objects_map_capacity(objects_map_t *map);
/* Performs an internal consistency check, returns 'true' if
* everything is OK, 'false' otherwise. Really useful only
* for debugging. */
int
objects_map_check_map (objects_map_t * map);
objects_map_check(objects_map_t *map);
/** Finding elements in a mapionary **/
/** Finding elements in a map... **/
/* Returns 'true' if and only if some key in MAP is equal
* (in the sense of the key callbacks of MAP) to KEY. */
int
objects_map_contains_key (objects_map_t * map, const void *key);
objects_map_contains_key(objects_map_t *map, const void *key);
/* Returns 'true' if and only if some value in MAP is equal
* (in the sense of the value callbacks of MAP) to VALUE. */
/* WARNING: This is rather inefficient. Not to be used lightly. */
int
objects_map_key_and_value (objects_map_t * map,
const void *key,
void **old_key,
void **value);
objects_map_contains_value(objects_map_t *map, const void *value);
/* If KEY is in MAP, then the following three things happen:
* (1) 'true' is returned;
* (2) if OLD_KEY is non-zero, then the key in MAP
* equal to KEY is placed there;
* (3) if VALUE is non-zero, then the value in MAP
* mapped to by KEY is placed there.
* If KEY is not in MAP, then the following three things happen:
* (1) 'false' is returned;
* (2) if OLD_KEY is non-zero, then the "not a key marker"
* for MAP is placed there;
* (3) if VALUE is non-zero, then the the "not a value marker"
* for MAP is placed there. */
int
objects_map_key_and_value_at_key(objects_map_t *map,
const void **old_key,
const void **value,
const void *key);
/* If KEY is in MAP, then the key of MAP which is equal to KEY
* is returned. Otherwise, the "not a key marker" for MAP is returned. */
const void *
objects_map_key (objects_map_t * map, const void *key);
objects_map_key_at_key(objects_map_t *map, const void *key);
/* If KEY is in MAP, then the value of MAP which to which KEY maps
* is returned. Otherwise, the "not a value marker" for MAP is returned. */
const void *
objects_map_value_at_key (objects_map_t * map, const void *key);
objects_map_value_at_key(objects_map_t *map, const void *key);
/** Enumerating the nodes and elements of a mapionary **/
/** Enumerating the nodes and elements of a map... **/
objects_map_enumerator_t
objects_map_enumerator (objects_map_t * map);
objects_map_enumerator_for_map(objects_map_t *map);
int
objects_map_enumerator_next_key_and_value (objects_map_enumerator_t *enumeratr,
const void **key,
const void **value);
objects_map_enumerator_next_key_and_value(objects_map_enumerator_t *enumerator,
const void **key,
const void **value);
int
objects_map_enumerator_next_key (objects_map_enumerator_t * enumerator,
const void **key);
objects_map_enumerator_next_key(objects_map_enumerator_t *enumerator,
const void **key);
int
objects_map_enumerator_next_value (objects_map_enumerator_t * enumerator,
const void **value);
objects_map_enumerator_next_value(objects_map_enumerator_t *enumerator,
const void **value);
/** Obtaining an array of the elements of a mapionary **/
/** Obtaining an array of the elements of a map... **/
const void **
objects_map_all_keys_and_values (objects_map_t * map);
objects_map_all_keys_and_values(objects_map_t *map);
const void **
objects_map_all_keys (objects_map_t * map);
objects_map_all_keys(objects_map_t *map);
const void **
objects_map_all_values (objects_map_t * map);
objects_map_all_values(objects_map_t *map);
/** Removing **/
/** Removing... **/
/* Removes the key/value pair (if any) from MAP whose key is KEY. */
void
objects_map_remove_key (objects_map_t * map, const void *key);
objects_map_remove_key(objects_map_t *map, const void *key);
/* Releases all of the keys and values of MAP without
* altering MAP's capacity. */
void
objects_map_empty (objects_map_t * map);
objects_map_empty(objects_map_t *map);
/** Adding **/
/** Adding... **/
const void *
objects_map_at_key_put_value_known_absent (objects_map_t * map,
const void *key,
const void *value);
objects_map_at_key_put_value_known_absent(objects_map_t *map,
const void *key,
const void *value);
const void *
objects_map_at_key_put_value (objects_map_t * map,
const void *key,
const void *value);
objects_map_at_key_put_value(objects_map_t *map,
const void *key,
const void *value);
const void *
objects_map_at_key_put_value_if_absent (objects_map_t * map,
const void *key,
const void *value);
objects_map_at_key_put_value_if_absent(objects_map_t *map,
const void *key,
const void *value);
/** Replacing **/
/** Replacing... **/
void
objects_map_replace_key (objects_map_t * map, const void *key);
objects_map_replace_key(objects_map_t *map, const void *key);
/** Comparing **/
/** Comparing... **/
/* Returns 'true' if every key/value pair of MAP2 is also a key/value pair
* of MAP1. Otherwise, returns 'false'. */
int
objects_map_contains_map (objects_map_t * map1, objects_map_t * map2);
objects_map_contains_map(objects_map_t *map1, objects_map_t *map2);
/* Returns 'true' if MAP1 and MAP2 have the same number of key/value pairs,
* MAP1 contains MAP2, and MAP2 contains MAP1. Otherwise, returns 'false'. */
int
objects_map_is_equal_to_map (objects_map_t * map1, objects_map_t * map2);
objects_map_is_equal_to_map(objects_map_t *map1, objects_map_t *map2);
/** Copying **/
/* Returns 'true' iff every key of MAP2 is a key of MAP1. */
int
objects_map_keys_contain_keys_of_map(objects_map_t *map1, objects_map_t *map2);
/* Returns 'true' if MAP1 and MAP2 have the same number of key/value pairs,
* MAP1 contains every key of MAP2, and MAP2 contains every key of MAP1.
* Otherwise, returns 'false'. */
int
objects_map_keys_are_equal_to_keys_of_map(objects_map_t *map1,
objects_map_t *map2);
/* Returns 'true' iff some key/value pair of MAP1 if also
* a key/value pair of MAP2. */
int
objects_map_intersects_map(objects_map_t *map1, objects_map_t *map2);
/* Returns 'true' iff some key of MAP1 if also a key of MAP2. */
int
objects_map_keys_intersect_keys_of_map(objects_map_t *map1,
objects_map_t *map2);
/** Copying... **/
/* Returns a copy of OLD_MAP in ZONE. Remember that, as far as what
* (if anything) OLD_MAP's keys and values point to, this copy is
* shallow. If, for example, OLD_MAP is a map from int to int, then
* you've got nothing more to worry about. If, however, OLD_MAP is a
* map from id to id, and you want the copy of OLD_MAP to be "deep",
* you'll need to use the mapping functions below to make copies of
* all of the returned map's elements. */
objects_map_t *
objects_map_copy_with_allocs (objects_map_t * old_map, objects_allocs_t new_allocs);
objects_map_copy_with_zone(objects_map_t *old_map, NSZone *zone);
/* Just like 'objects_map_copy_with_zone()', but returns a copy of
* OLD_MAP in the default zone. */
objects_map_t *
objects_map_copy (objects_map_t * old_map);
objects_map_copy(objects_map_t *old_map);
/** Mapping **/
/** Mapping... **/
/* WARNING: The mapping function KFCN must be one-to-one on the keys
* of MAP. I.e., `objects_map_map_keys()' makes no provision for the
* possibility that KFCN maps two unequal keys of MAP to the same (or
* equal) keys. */
/* Iterates through MAP, replacing each key with the result of
* '(*kfcn)(key, user_data)'. Useful for deepening copied maps
* and other uniform (and one-to-one) transformations of map keys. */
/* WARNING: The mapping function KFCN *must* be one-to-one on the
* (equivalence classes of) keys of MAP. I.e., for efficiency's sake,
* `objects_map_map_keys()' makes no provision for the possibility
* that KFCN maps two unequal keys of MAP to the same (or equal) keys. */
objects_map_t *
objects_map_map_keys (objects_map_t * map,
const void *(*kfcn) (const void *, const void *),
const void *user_data);
objects_map_map_keys(objects_map_t *map,
const void *(*kfcn)(const void *, void *),
void *user_data);
/* Iterates through MAP, replacing each value with the result of
* '(*vfcn)(value, user_data)'. Useful for deepening copied maps
* and other uniform transformations of map keys. */
/* NO WARNING: The mapping function VFCN need not be one-to-one on
* (the equivalence classes of) values. */
objects_map_t *
objects_map_map_values (objects_map_t * map,
const void *(*vfcn) (const void *, const void *),
const void *user_data);
objects_map_map_values(objects_map_t *map,
const void *(*vfcn)(const void *, void *),
void *user_data);
/** Miscellaneous **/
/** Resizing... **/
/* Resizes MAP to be ready to contain (at least) NEW_CAPACITY many elements.
* However, as far as you are concerned, it is indeterminate what exactly
* this means. After receiving and successfully processing this call,
* you are *not* guaranteed that MAP has actually set aside space for
* NEW_CAPACITY elements, for example. All that you are guaranteed is that,
* to the best of its ability, MAP will incur no loss in efficiency so long
* as it contains no more than NEW_CAPACITY elements. */
size_t
objects_map_resize(objects_map_t *map, size_t new_capacity);
/* Shrinks (or grows) MAP to be comfortable with the number of elements
* it contains. In all likelyhood, after this call, MAP is more efficient
* in terms of its speed of search vs. use of space balance. */
size_t
objects_map_rightsize(objects_map_t *map);
/** Describing... **/
/* Returns a string describing (the contents of) MAP. */
NSString *
objects_map_description(objects_map_t *map);
/** Set theoretic operations... **/
objects_map_t *
objects_map_intersect_map (objects_map_t * map, objects_map_t * other_map);
objects_map_intersect_map(objects_map_t *map, objects_map_t *other_map);
objects_map_t *
objects_map_minus_map (objects_map_t * map, objects_map_t * other_map);
objects_map_minus_map(objects_map_t *map, objects_map_t *other_map);
objects_map_t *
objects_map_union_map (objects_map_t * map, objects_map_t * other_map);
objects_map_union_map(objects_map_t *map, objects_map_t *other_map);
objects_hash_t *
objects_hash_init_from_map_keys (objects_hash_t * hash, objects_map_t * map);
objects_hash_init_from_map_keys(objects_hash_t *hash, objects_map_t *map);
objects_hash_t *
objects_hash_init_from_map_values (objects_hash_t * hash, objects_map_t * map);
objects_hash_init_from_map_values(objects_hash_t *hash, objects_map_t *map);
#endif /* __map_h_OBJECTS_INCLUDE */

View file

@ -1,51 +0,0 @@
/* GCC macros for minimum and maximum.
* Copyright (C) 1996 Free Software Foundation, Inc.
*
* Author: Albin L. Jones <Albin.L.Jones@Dartmouth.EDU>
* Created: Sat Feb 10 21:13:04 EST 1996
* Updated: Sat Feb 10 21:13:04 EST 1996
* Serial: 96.02.10.01
*
* This file is part of the GNU Objective C Class Library.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the Free
* Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*
*/
#ifndef __minmax_h_OBJECTS_INCLUDE
#define __minmax_h_OBJECTS_INCLUDE 1
/**** Included Headers *******************************************************/
/**** Type, Constant, and Macro Definitions **********************************/
#ifdef MIN
#undef MIN
#endif /* !MIN */
#define MIN(X, Y) \
({ typeof (X) __x = (X), __y = (Y); \
(__x < __y) ? __x : __y; })
#ifdef MAX
#undef MAX
#endif /* !MAX */
#define MAX(X, Y) \
({ typeof (X) __x = (X), __y = (Y); \
(__x > __y) ? __x : __y; })
#endif /* __minmax_h_OBJECTS_INCLUDE */

View file

@ -1,49 +0,0 @@
/* Structure counters and functions for getting at them.
* Copyright (C) 1995, 1996 Free Software Foundation, Inc.
*
* Author: Albin L. Jones <Albin.L.Jones@Dartmouth.EDU>
* Created: Sun Dec 3 00:28:01 EST 1995
* Updated: Sat Feb 10 15:51:02 EST 1996
* Serial: 96.02.10.01
*
* This file is part of the GNU Objective C Class Library.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the Free
* Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*
*/
#ifndef __number_h_OBJECTS_INCLUDE
#define __number_h_OBJECTS_INCLUDE 1
/**** Included Headers *******************************************************/
#include <stdlib.h>
/**** Type, Constant, and Macro Definitions **********************************/
extern size_t ___objects_number_allocated;
extern size_t ___objects_number_deallocated;
extern size_t ___objects_number_serial;
/**** Function Prototypes ****************************************************/
size_t _objects_number_allocated(void);
size_t _objects_number_deallocated(void);
size_t _objects_number_serial(void);
#endif /* __number_h_OBJECTS_INCLUDE */

View file

@ -1,10 +1,10 @@
/* A sparse array for use with Libobjects.
/* A sparse array structure.
* Copyright (C) 1994, 1995, 1996 Free Software Foundation, Inc.
*
* Author: Albin L. Jones <Albin.L.Jones@Dartmouth.EDU>
* Created: Thu Mar 2 02:30:02 EST 1994
* Updated: Sat Feb 10 15:38:58 EST 1996
* Serial: 96.02.10.01
* Updated: Tue Mar 12 02:42:54 EST 1996
* Serial: 96.03.12.13
*
* This file is part of the GNU Objective C Class Library.
*
@ -20,9 +20,7 @@
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the Free
* Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*
*/
* Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
#ifndef __array_h_OBJECTS_INCLUDE
#define __array_h_OBJECTS_INCLUDE 1
@ -30,7 +28,7 @@
/**** Included Headers *******************************************************/
#include <stdlib.h>
#include <objects/allocs.h>
#include <Foundation/NSZone.h>
#include <objects/callbacks.h>
#include <objects/hash.h>
@ -42,157 +40,209 @@ typedef objects_array_bucket_t *objects_array_slot_t;
typedef struct _objects_array_enumerator objects_array_enumerator_t;
struct _objects_array_bucket
{
/* The bucket's real (or external) index */
size_t index;
{
/* The bucket's real (or external) index */
size_t index;
/* The bucket's cargo */
const void *element;
};
/* The bucket's cargo */
const void *element;
};
struct _objects_array
{
/* Identifying information. */
int magic;
size_t number;
const char *name;
const void *extra;
objects_callbacks_t extra_callbacks;
objects_allocs_t allocs;
{
/* Identifying information. */
int magic_number;
size_t serial_number;
NSZone *zone;
NSString *name;
const void *extra;
objects_callbacks_t extra_callbacks;
/* Callbacks for the items in the array. */
objects_callbacks_t callbacks;
/* Callbacks for the items in the array. */
objects_callbacks_t callbacks;
/* Internal counters */
size_t slot_count;
size_t element_count;
/* Internal counters */
size_t slot_count;
size_t element_count;
/* Databanks */
objects_array_slot_t *slots;
objects_array_slot_t *sorted_slots;
};
/* Databanks */
objects_array_slot_t *slots;
objects_array_slot_t *sorted_slots;
};
struct _objects_array_enumerator
{
objects_array_t * array;
size_t index;
int is_sorted;
int is_ascending;
};
{
objects_array_t *array;
size_t index;
int is_sorted;
int is_ascending;
};
/**** Function Prototypes ****************************************************/
/** Basics **/
#include <objects/array-basics.h>
#include <objects/array-callbacks.h>
#include <objects/array-bas.h>
#include <objects/array-cbs.h>
/** Creating **/
objects_array_t * objects_array_alloc (void);
objects_array_t *
objects_array_alloc(void);
objects_array_t * objects_array_alloc_with_allocs (objects_allocs_t allocs);
objects_array_t *
objects_array_alloc_with_zone(NSZone *zone);
objects_array_t * objects_array (void);
objects_array_t *
objects_array(void);
objects_array_t * objects_array_with_allocs (objects_allocs_t allocs);
objects_array_t *
objects_array_with_zone(NSZone *zone);
objects_array_t * objects_array_with_allocs_with_callbacks (objects_allocs_t allocs, objects_callbacks_t callbacks);
objects_array_t *
objects_array_with_zone_with_callbacks(NSZone *zone,
objects_callbacks_t callbacks);
objects_array_t * objects_array_with_callbacks (objects_callbacks_t callbacks);
objects_array_t *
objects_array_with_callbacks(objects_callbacks_t callbacks);
objects_array_t * objects_array_of_char_p (void);
objects_array_t *
objects_array_of_char_p(void);
objects_array_t * objects_array_of_void_p (void);
objects_array_t *
objects_array_of_non_owned_void_p(void);
objects_array_t * objects_array_of_owned_void_p (void);
objects_array_t *
objects_array_of_owned_void_p(void);
objects_array_t * objects_array_of_int (void);
objects_array_t *
objects_array_of_int(void);
objects_array_t * objects_array_of_id (void);
objects_array_t *
objects_array_of_id(void);
/** Initializing **/
objects_array_t * objects_array_init (objects_array_t * array);
objects_array_t *
objects_array_init(objects_array_t *array);
objects_array_t * objects_array_init_with_callbacks (objects_array_t * array, objects_callbacks_t callbacks);
objects_array_t *
objects_array_init_with_callbacks(objects_array_t *array,
objects_callbacks_t callbacks);
objects_array_t * objects_array_init_with_array (objects_array_t * array, objects_array_t * other_array);
objects_array_t *
objects_array_init_with_array(objects_array_t *array,
objects_array_t *other_array);
/** Copying **/
objects_array_t * objects_array_copy (objects_array_t * array);
objects_array_t *
objects_array_copy(objects_array_t *array);
objects_array_t * objects_array_copy_with_allocs (objects_array_t * array, objects_allocs_t allocs);
objects_array_t *
objects_array_copy_with_zone(objects_array_t *array, NSZone *zone);
/** Destroying **/
void objects_array_dealloc (objects_array_t * array);
void
objects_array_dealloc(objects_array_t *array);
/** Comparing **/
int objects_array_is_equal_to_array (objects_array_t * array, objects_array_t * other_array);
int
objects_array_is_equal_to_array(objects_array_t *array,
objects_array_t *other_array);
/** Adding **/
const void *objects_array_at_index_put_element (objects_array_t * array, size_t index, const void *element);
const void *
objects_array_at_index_put_element(objects_array_t *array,
size_t index,
const void *element);
/** Replacing **/
/** Removing **/
void objects_array_remove_element_at_index (objects_array_t * array, size_t index);
void
objects_array_remove_element_at_index(objects_array_t *array, size_t index);
void objects_array_remove_element (objects_array_t * array, const void *element);
void
objects_array_remove_element(objects_array_t *array, const void *element);
void objects_array_remove_element_known_present (objects_array_t * array, const void *element);
void
objects_array_remove_element_known_present(objects_array_t *array,
const void *element);
/** Emptying **/
void objects_array_empty (objects_array_t * array);
void
objects_array_empty(objects_array_t *array);
/** Searching **/
int objects_array_contains_element (objects_array_t * array, const void *element);
int
objects_array_contains_element(objects_array_t *array, const void *element);
const void *objects_array_element (objects_array_t * array, const void *element);
const void *
objects_array_element(objects_array_t *array, const void *element);
size_t objects_array_index_of_element (objects_array_t * array, const void *element);
size_t
objects_array_index_of_element(objects_array_t *array, const void *element);
const void *objects_array_element_at_index (objects_array_t * array, size_t index);
const void *
objects_array_element_at_index(objects_array_t *array, size_t index);
const void **objects_array_all_elements (objects_array_t * array);
const void **
objects_array_all_elements(objects_array_t *array);
const void **objects_array_all_elements_ascending (objects_array_t * array);
const void **
objects_array_all_elements_ascending(objects_array_t *array);
const void **objects_array_all_element_descending (objects_array_t * array);
const void **
objects_array_all_element_descending(objects_array_t *array);
/** Enumerating **/
objects_array_enumerator_t objects_array_enumerator (objects_array_t * array);
objects_array_enumerator_t
objects_array_enumerator(objects_array_t *array);
objects_array_enumerator_t objects_array_ascending_enumerator (objects_array_t * array);
objects_array_enumerator_t
objects_array_ascending_enumerator(objects_array_t *array);
objects_array_enumerator_t objects_array_descending_enumerator (objects_array_t * array);
objects_array_enumerator_t
objects_array_descending_enumerator(objects_array_t *array);
int objects_array_enumerator_next_index_and_element (objects_array_enumerator_t *enumerator, size_t *index, const void **element);
int
objects_array_enumerator_next_index_and_element(objects_array_enumerator_t *enumerator,
size_t *index,
const void **element);
int objects_array_enumerator_next_element (objects_array_enumerator_t *enumerator, const void **element);
int
objects_array_enumerator_next_element(objects_array_enumerator_t *enumerator,
const void **element);
int objects_array_enumerator_next_index (objects_array_enumerator_t *enumerator, size_t *element);
int
objects_array_enumerator_next_index(objects_array_enumerator_t *enumerator,
size_t *element);
/** Statistics **/
int objects_array_is_empty (objects_array_t * array);
int
objects_array_is_empty(objects_array_t *array);
size_t objects_array_count (objects_array_t * array);
size_t
objects_array_count(objects_array_t *array);
size_t objects_array_capacity (objects_array_t * array);
size_t
objects_array_capacity(objects_array_t *array);
int objects_array_check (objects_array_t * array);
int
objects_array_check(objects_array_t *array);
/** Miscellaneous **/
objects_hash_t *objects_hash_init_from_array (objects_hash_t *hash, objects_array_t *array);
objects_hash_t *
objects_hash_init_from_array(objects_hash_t *hash, objects_array_t *array);
#endif /* __array_h_OBJECTS_INCLUDE */

View file

@ -3,8 +3,8 @@
*
* Author: Albin L. Jones <Albin.L.Jones@Dartmouth.EDU>
* Created: Sun Oct 9 13:18:50 EDT 1994
* Updated: Sun Feb 11 01:46:03 EST 1996
* Serial: 96.02.11.01
* Updated: Mon Mar 11 00:31:13 EST 1996
* Serial: 96.03.11.01
*
* This file is part of the GNU Objective C Class Library.
*
@ -20,9 +20,7 @@
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the Free
* Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*
*/
* Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
#ifndef __callbacks_h_OBJECTS_INCLUDE
#define __callbacks_h_OBJECTS_INCLUDE 1
@ -30,17 +28,16 @@
/**** Included Headers *******************************************************/
#include <stdlib.h>
#include <Foundation/NSString.h>
/**** Type, Constant, and Macro Definitions **********************************/
typedef size_t (*objects_hash_func_t) (const void *, const void *);
typedef int (*objects_compare_func_t) (const void *, const void *,
const void *);
typedef int (*objects_is_equal_func_t) (const void *, const void *,
const void *);
typedef void *(*objects_retain_func_t) (const void *, const void *);
typedef void (*objects_release_func_t) (void *, const void *);
typedef void *(*objects_describe_func_t) (const void *, const void *);
typedef size_t (*objects_hash_func_t)(const void *, void *);
typedef int (*objects_compare_func_t)(const void *, const void *, void *);
typedef int (*objects_is_equal_func_t)(const void *, const void *, void *);
typedef const void *(*objects_retain_func_t)(const void *, void *);
typedef void (*objects_release_func_t)(void *, void *);
typedef NSString *(*objects_describe_func_t)(const void *, void *);
typedef struct _objects_callbacks objects_callbacks_t;
@ -59,7 +56,7 @@ struct _objects_callbacks
extern const objects_callbacks_t objects_callbacks_for_int;
extern const objects_callbacks_t objects_callbacks_for_char_p;
extern const objects_callbacks_t objects_callbacks_for_void_p;
extern const objects_callbacks_t objects_callbacks_for_non_owned_void_p;
extern const objects_callbacks_t objects_callbacks_for_owned_void_p;
extern const objects_callbacks_t objects_callbacks_for_int_p;
extern const objects_callbacks_t objects_callbacks_for_id;
@ -78,97 +75,105 @@ extern objects_callbacks_t __objects_callbacks_standard;
/** Generic callbacks **/
/* Returns `__objects_callbacks_standard', defined above. */
/* Returns the programmer-alterable `__objects_callbacks_standard',
* defined above. */
objects_callbacks_t
objects_callbacks_standard (void);
objects_callbacks_standard(void);
/** Standardizing callbacks **/
/* Makes sure that enough of CALLBACKS is defined (i.e., non-zero)
* to be used. This is used, rather than local checks for usability,
* to improve the efficiency of callback use. */
objects_callbacks_t
objects_callbacks_standardize (objects_callbacks_t callbacks);
objects_callbacks_standardize(objects_callbacks_t callbacks);
/** Using callbacks **/
size_t objects_hash (objects_callbacks_t callbacks,
const void *thing,
const void *user_data);
size_t
objects_hash(objects_callbacks_t callbacks,
const void *thing,
void *user_data);
int objects_compare (objects_callbacks_t callbacks,
const void *thing1,
const void *thing2,
const void *user_data);
int
objects_compare(objects_callbacks_t callbacks,
const void *thing1,
const void *thing2,
void *user_data);
int objects_is_equal (objects_callbacks_t callbacks,
const void *thing1,
const void *thing2,
const void *user_data);
int
objects_is_equal(objects_callbacks_t callbacks,
const void *thing1,
const void *thing2,
void *user_data);
void *objects_retain (objects_callbacks_t callbacks,
const void *thing,
const void *user_data);
const void *
objects_retain(objects_callbacks_t callbacks,
const void *thing,
void *user_data);
void objects_release (objects_callbacks_t callbacks,
void *thing,
const void *user_data);
void
objects_release(objects_callbacks_t callbacks,
void *thing,
void *user_data);
/* FIXME: Decide what to do with this describe stuff. We'd really like
* them to return Strings? Or would we rather they be `char *'s?
* Or something else? */
void *objects_describe (objects_callbacks_t callbacks,
const void *thing,
const void *user_data);
NSString *
objects_describe(objects_callbacks_t callbacks,
const void *thing,
void *user_data);
const void *objects_not_an_item_marker (objects_callbacks_t);
const void *
objects_not_an_item_marker(objects_callbacks_t callbacks);
/** Specific callback functions **/
/** Specific callback functions... **/
/* For `void *' */
size_t objects_void_p_hash(const void *ptr);
int objects_void_p_compare(const void *ptr, const void *qtr);
int objects_void_p_is_equal(const void *ptr, const void *qtr);
const void *objects_void_p_retain(const void *ptr);
void objects_void_p_release(const void *ptr);
const void *objects_void_p_describe(const void *ptr);
/* For non-owned `void *' */
size_t objects_non_owned_void_p_hash(const void *ptr);
int objects_non_owned_void_p_compare(const void *ptr, const void *qtr);
int objects_non_owned_void_p_is_equal(const void *ptr, const void *qtr);
const void *objects_non_owned_void_p_retain(const void *ptr);
void objects_non_owned_void_p_release(void *ptr);
NSString *objects_non_owned_void_p_describe(const void *ptr);
/* For `void *' */
/* For owned `void *' */
size_t objects_owned_void_p_hash(const void *ptr);
int objects_owned_void_p_compare(const void *ptr, const void *qtr);
int objects_owned_void_p_is_equal(const void *ptr, const void *qtr);
const void *objects_owned_void_p_retain(const void *ptr);
void objects_owned_void_p_release(const void *ptr);
const void *objects_owned_void_p_describe(const void *ptr);
void objects_owned_void_p_release(void *ptr);
NSString *objects_owned_void_p_describe(const void *ptr);
/* For `int' */
size_t objects_int_hash(const void *i);
int objects_int_compare(const void *i, const void *j);
int objects_int_is_equal(const void *i, const void *j);
const void *objects_int_retain(const void *i);
void objects_int_release(const void *i);
const void *objects_int_describe(const void *i);
size_t objects_int_hash(int i);
int objects_int_compare(int i, int j);
int objects_int_is_equal(int i, int j);
const void *objects_int_retain(int i);
void objects_int_release(int i);
NSString *objects_int_describe(int i);
/* For `int *' */
size_t objects_int_p_hash(const void *iptr);
int objects_int_p_compare(const void *iptr, const void *jptr);
int objects_int_p_is_equal(const void *iptr, const void *jptr);
const void *objects_int_p_retain(const void *iptr);
void objects_int_p_release(const void *iptr);
const void *objects_int_p_describe(const void *iptr);
size_t objects_int_p_hash(const int *iptr);
int objects_int_p_compare(const int *iptr, const int *jptr);
int objects_int_p_is_equal(const int *iptr, const int *jptr);
const void *objects_int_p_retain(const int *iptr);
void objects_int_p_release(int *iptr);
NSString *objects_int_p_describe(const int *iptr);
/* For `char *' */
size_t objects_char_p_hash(const void *cptr);
int objects_char_p_compare(const void *cptr, const void *dptr);
int objects_char_p_is_equal(const void *cptr, const void *dptr);
const void *objects_char_p_retain(const void *cptr);
void objects_char_p_release(const void *cptr);
const void *objects_char_p_describe(const void *cptr);
size_t objects_char_p_hash(const char *cptr);
int objects_char_p_compare(const char *cptr, const char *dptr);
int objects_char_p_is_equal(const char *cptr, const char *dptr);
const void *objects_char_p_retain(const char *cptr);
void objects_char_p_release(char *cptr);
NSString *objects_char_p_describe(const char *cptr);
/* For `id' */
size_t objects_id_hash(const void *obj);
int objects_id_compare(const void *obj, const void *jbo);
int objects_id_is_equal(const void *obj, const void *jbo);
const void *objects_id_retain(const void *obj);
void objects_id_release(const void *obj);
const void *objects_id_describe(const void *obj);
size_t objects_id_hash(id obj);
int objects_id_compare(id obj, id jbo);
int objects_id_is_equal(id obj, id jbo);
const void *objects_id_retain(id obj);
void objects_id_release(id obj);
NSString *objects_id_describe(id obj);
#endif /* __callbacks_h_OBJECTS_INCLUDE */

View file

@ -1,10 +1,10 @@
/* A hash table for use with Libobjects.
/* A hash table.
* Copyright (C) 1993, 1994, 1995, 1996 Free Software Foundation, Inc.
*
* Author: Albin L. Jones <Albin.L.Jones@Dartmouth.EDU>
* Created: ??? ??? ?? ??:??:?? ??? 1993
* Updated: Sat Feb 10 15:35:37 EST 1996
* Serial: 96.02.10.01
* Updated: Tue Mar 19 00:25:34 EST 1996
* Serial: 96.03.19.05
*
* This file is part of the GNU Objective C Class Library.
*
@ -20,208 +20,374 @@
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the Free
* Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*
*/
* Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
#ifndef __hash_h_OBJECTS_INCLUDE
#define __hash_h_OBJECTS_INCLUDE 1
/**** Included Headers *******************************************************/
#include <objects/allocs.h>
#include <Foundation/NSZone.h>
#include <Foundation/NSString.h>
#include <objects/callbacks.h>
/**** Type, Constant, and Macro Definitions **********************************/
/* Need these up here because of their interdependence. */
typedef struct _objects_hash objects_hash_t;
typedef struct _objects_hash_bucket objects_hash_bucket_t;
typedef struct _objects_hash_node objects_hash_node_t;
typedef struct _objects_hash_enumerator objects_hash_enumerator_t;
typedef struct _objects_hash_node objects_hash_node_t;
typedef struct _objects_hash_bucket objects_hash_bucket_t;
/* Private type for elemental holding. */
struct _objects_hash_node
{
objects_hash_t *hash;
objects_hash_bucket_t *bucket;
{
/* The hash table with which the node is associated. */
objects_hash_t *hash;
objects_hash_node_t *next_in_bucket;
objects_hash_node_t *prev_in_bucket;
objects_hash_node_t *next_in_hash;
objects_hash_node_t *prev_in_hash;
/* The bucket in HASH in which the node sits. */
objects_hash_bucket_t *bucket;
const void *element;
};
/* These hold the BUCKET linked list together. */
objects_hash_node_t *next_in_bucket;
objects_hash_node_t *prev_in_bucket;
/* For enumerating over the whole hash table. These make
* enumerating much quicker. They also make it safer. */
objects_hash_node_t *next_in_hash;
objects_hash_node_t *prev_in_hash;
/* What the node is holding for us. Its raison d'etre. */
const void *element;
};
/* Private type for holding chains of nodes. */
struct _objects_hash_bucket
{
size_t node_count;
size_t element_count;
{
/* The number of nodes in this bucket. For internal consistency checks. */
size_t node_count;
objects_hash_node_t *first_node;
};
/* The number of elements in this bucket. (This had *better* be
* the same as NODE_COUNT, or something's wrong.) */
size_t element_count;
/* The head of this bucket's linked list of nodes. */
objects_hash_node_t *first_node;
};
/* The hash table type. */
struct _objects_hash
{
int magic;
size_t number;
const char *name;
const void *extra;
objects_callbacks_t extra_callbacks;
objects_allocs_t allocs;
{
/* All structures have these...
* And all structures have them in the same order. */
int magic_number;
size_t serial_number;
NSZone *zone;
NSString *name;
const void *extra;
objects_callbacks_t extra_callbacks;
/* Callbacks for the items in the hash. */
objects_callbacks_t callbacks;
/* Callbacks for the elements of the hash. */
objects_callbacks_t callbacks;
/* Internal hash counters. */
size_t bucket_count; /* How many types of items? */
size_t node_count; /* How many items? */
size_t element_count; /* How many elements? */
/* Internal counters. Mainly for consistency's sake. */
size_t bucket_count; /* How many types of items? */
size_t node_count; /* How many items? */
size_t element_count; /* How many elements? */
/* Places to start looking for elements. */
objects_hash_bucket_t *buckets;
objects_hash_node_t *first_node;
};
/* Places to start looking for elements. */
objects_hash_bucket_t *buckets; /* Organized as a hash. */
objects_hash_node_t *first_node; /* Organized as a linked list.
* (For enumerating...) */
};
/* Type for enumerating the elements of a hash table. */
struct _objects_hash_enumerator
{
objects_hash_t *hash;
objects_hash_node_t *node;
};
{
objects_hash_t *hash; /* To which hash do I belong? */
objects_hash_node_t *node; /* Which node is next? */
};
/**** Function Prototypes ****************************************************/
/** Basics **/
/** Basics... **/
#include <objects/hash-basics.h>
#include <objects/hash-callbacks.h>
/* All the structures (hashes, maps, lists, and arrays) have
* the same basic ideas behind them. */
/** Hashing **/
#include <objects/hash-bas.h>
#include <objects/hash-cbs.h>
size_t objects_hash_hash (objects_hash_t * hash);
/** Callbacks... **/
/** Creating **/
/* Returns a collection of callbacks for use with hash tables. */
objects_callbacks_t
objects_callbacks_for_hash(void);
objects_hash_t * objects_hash_alloc (void);
/** Creating... **/
objects_hash_t * objects_hash_alloc_with_allocs (objects_allocs_t alloc);
/* Allocate a hash table in the default zone. */
objects_hash_t *
objects_hash_alloc(void);
objects_hash_t * objects_hash_with_callbacks (objects_callbacks_t callbacks);
/* Allocate a hash table in the memory block ZONE. */
objects_hash_t *
objects_hash_alloc_with_zone(NSZone *zone);
objects_hash_t * objects_hash_with_allocs (objects_allocs_t allocs);
/* Create an empty hash table in the memory block ZONE. The returned
* hash table has a "reasonable" default capacity, but will need to
* be resized to suit your specific needs if more than a couple of
* dozen elements will be placed within it. */
objects_hash_t *
objects_hash_with_zone_with_callbacks(NSZone *zone,
objects_callbacks_t callbacks);
objects_hash_t * objects_hash_with_allocs_with_callbacks (objects_allocs_t allocs, objects_callbacks_t callbacks);
/* Like calling 'objects_hash_with_zone_with_callbacks(zone,
* objects_callbacks_standard())'. */
objects_hash_t *
objects_hash_with_zone(NSZone *zone);
objects_hash_t * objects_hash_of_char_p (void);
/* Like calling 'objects_hash_with_zone_with_callbacks(0, callbacks)'. */
objects_hash_t *
objects_hash_with_callbacks(objects_callbacks_t callbacks);
objects_hash_t * objects_hash_of_void_p (void);
/* These are just shortcuts for ease of use. */
objects_hash_t *objects_hash_of_char_p(void);
objects_hash_t *objects_hash_of_non_owned_void_p(void);
objects_hash_t *objects_hash_of_owned_void_p(void);
objects_hash_t *objects_hash_of_int(void);
objects_hash_t *objects_hash_of_int_p(void);
objects_hash_t *objects_hash_of_id(void);
objects_hash_t * objects_hash_of_owned_void_p (void);
/** Initializing... **/
objects_hash_t * objects_hash_of_int (void);
/* Initializes HASH with a "reasonable" capacity, with the
* callbacks obtained from 'objects_callbacks_standard()'. */
objects_hash_t *
objects_hash_init(objects_hash_t *hash);
objects_hash_t * objects_hash_of_id (void);
/* Initializes HASH with a "reasonable" capacity and
* with element callbacks CALLBACKS. */
objects_hash_t *
objects_hash_init_with_callbacks(objects_hash_t *hash,
objects_callbacks_t callbacks);
/** Initializing **/
/* Initializes HASH with the capacity, callbacks, and contents
* of OTHER_HASH. NOTE: This is (as it must be) a "shallow" copying.
* See 'objects_hash_copy_with_zone()', below. */
objects_hash_t *
objects_hash_init_with_hash(objects_hash_t *hash,
objects_hash_t *other_hash);
objects_hash_t * objects_hash_init (objects_hash_t * hash);
/** Copying... **/
objects_hash_t * objects_hash_init_with_callbacks (objects_hash_t * hash, objects_callbacks_t callbacks);
/* Creates a (shallow) copy of HASH in the memory block ZONE. WARNING:
* If the elements of HASH are pointers to mutable items, it is the
* programmer's responsibility to deepen the copy returned by this
* function call (using, for example, `objects_hash_map_elements()'). */
objects_hash_t *
objects_hash_copy_with_zone(objects_hash_t *hash, NSZone *zone);
objects_hash_t * objects_hash_init_with_hash (objects_hash_t * hash, objects_hash_t * other_hash);
/* Create a (shallow) copy of HASH in the default zone. WARNING: See the
* above function for an important caveat about copying. */
objects_hash_t *
objects_hash_copy(objects_hash_t *old_hash);
/** Copying **/
objects_hash_t * objects_hash_copy (objects_hash_t * old_hash);
objects_hash_t * objects_hash_copy_with_allocs (objects_hash_t * hash, objects_allocs_t new_allocs);
/** Mapping **/
/** Mapping... **/
/* WARNING: The mapping function FCN must be one-to-one on elements of
* HASH. I.e., for reasons of efficiency, `objects_hash_map_elements()'
* makes no provision for the possibility that FCN maps two unequal
* elements of HASH to the same (or equal) elements. The better way
* elements of HASH to the same (or "equal") elements. The better way
* to handle functions that aren't one-to-one is to create a new hash
* and transform the elements of the first to create the elements of
* the second. */
objects_hash_t *
objects_hash_map_elements (objects_hash_t * hash,
const void *(*fcn) (const void *, const void *),
const void *user_data);
* the second (by manual enumeration). */
objects_hash_t *
objects_hash_map_elements(objects_hash_t *hash,
const void *(*fcn)(const void *, const void *),
const void *user_data);
/** Destroying **/
/** Destroying... **/
void objects_hash_dealloc (objects_hash_t * hash);
/* Releases all the elements of HASH, and then frees up the space
* HASH used. HASH is no longer a (pointer to a) valid hash
* table structure after this call. */
void
objects_hash_dealloc(objects_hash_t *hash);
/** Comparing **/
/** Comparing... **/
int objects_hash_contains_hash (objects_hash_t * hash, objects_hash_t * other_hash);
/* Returns 'true' if every element of OTHER_HASH is also
* a member of HASH. Otherwise, returns 'false'. */
int
objects_hash_contains_hash(objects_hash_t *hash,
objects_hash_t *other_hash);
int objects_hash_intersects_hash (objects_hash_t * hash, objects_hash_t * other_hash);
/* Returns 'true' if some element of HASH is also
* a member of OTHER_HASH. Otherwise, returns 'false'. */
int
objects_hash_intersects_hash(objects_hash_t *hash,
objects_hash_t *other_hash);
int objects_hash_is_equal_to_hash (objects_hash_t * hash, objects_hash_t * other_hash);
/* Returns 'true' if HASH and OTHER_HASH have the same number of elements,
* HASH contains OTHER_HASH, and OTHER_HASH contains HASH. Otheraise, returns 'false'. */
int
objects_hash_is_equal_to_hash(objects_hash_t *hash,
objects_hash_t *other_hash);
/** Adding **/
/** Adding... **/
const void *objects_hash_add_element_known_absent (objects_hash_t *hash,
const void *element);
/* Adds ELEMENT to HASH. If ELEMENT is "equal" to an item already in HASH,
* then we abort. If ELEMENT is the "not an element marker" for HASH,
* then we abort. [NOTE: This abortive behaviour will be changed in a
* future revision.] */
const void *
objects_hash_add_element_known_absent(objects_hash_t *hash,
const void *element);
const void *objects_hash_add_element (objects_hash_t *hash,
const void *element);
/* Adds ELEMENT to HASH. If ELEMENT is "equal" to an item already in HASH,
* then that older item is released using the 'release()' callback function
* that was specified when HASH was created. (If ELEMENT is the "not an
* element marker" for HASH, then all bets are off, and we abort.
* [NOTE: This abortive behaviour will be changed in a future revision.]) */
const void *
objects_hash_add_element(objects_hash_t *hash, const void *element);
const void *objects_hash_add_element_if_absent (objects_hash_t *hash,
const void *element);
/* If (any item "equal" to) ELEMENT is in HASH, then that member of HASH is
* returned. Otherwise, the "not an element marker" for HASH is returned
* and ELEMENT is added to HASH. If ELEMENT is the "not an element marker"
* for HASH, then we abort. [NOTE: This abortive behaviour will be changed
* in a future revision.] */
const void *
objects_hash_add_element_if_absent(objects_hash_t *hash, const void *element);
/** Replacing **/
/** Replacing... **/
void objects_hash_replace_element (objects_hash_t *hash, const void *element);
/* If (some item "equal" to) ELEMENT is an element of HASH, then ELEMENT is
* substituted for it. The old element is released. (This is rather
* like the non-existant but perfectly reasonable function
* 'objects_hash_add_element_if_present()'.) */
void
objects_hash_replace_element(objects_hash_t *hash,
const void *element);
/** Removing **/
/** Removing... **/
void objects_hash_remove_element (objects_hash_t *hash, const void *element);
/* Removes the element (if any) of HASH which is "equal" to ELEMENT,
* according to HASH's element callbacks. It is not an error to
* remove ELEMENT from HASH, if no element of HASH is "equal" to ELEMENT. */
void
objects_hash_remove_element(objects_hash_t *hash, const void *element);
/** Emptying **/
/** Emptying... **/
void objects_hash_empty (objects_hash_t *hash);
/* Empties HASH, releasing all of its elements while retaining
* its current "capacity". */
void
objects_hash_empty(objects_hash_t *hash);
/** Searching **/
/** Searching... **/
void *objects_hash_any_element (objects_hash_t *hash);
/* Returns a "random" element of HASH, for your viewing enjoyment. */
void *
objects_hash_any_element(objects_hash_t *hash);
int objects_hash_contains_element (objects_hash_t *hash, const void *element);
/* Returns `true' if some element of HASH is "equal" to ELEMENT,
* according to HASH's element callbacks. */
int
objects_hash_contains_element(objects_hash_t *hash, const void *element);
const void *objects_hash_element (objects_hash_t *hash, const void *element);
/* Returns the element of HASH (or the appropriate `not an element
* marker' if there is none) which is "equal" to ELEMENT. */
const void *
objects_hash_element(objects_hash_t *hash, const void *element);
const void **objects_hash_all_elements (objects_hash_t *hash);
/* Returns an array with all the elements of HASH, terminated
* by HASH's "not an element marker". It is your responsibility
* to free the returned array. [NOTE: this responsibility may
* shift from your shoulders in a later revision.] */
const void **
objects_hash_all_elements(objects_hash_t *hash);
/** Enumerating **/
/** Enumerating... **/
objects_hash_enumerator_t objects_hash_enumerator (objects_hash_t *hash);
/* Returns an enumerator for HASH's elements. WARNING: DO NOT ALTER
* A HASH DURING AN ENUMERATION. DOING SO WILL PROBABLY LEAVE YOUR ENUMERATION
* IN AN INDETERMINATE STATE. If you are hell-bent on ignoring the above
* warning, please check out the source code for some more specific
* information about when and how one can get away with it. */
objects_hash_enumerator_t
objects_hash_enumerator_for_hash(objects_hash_t *hash);
int objects_hash_enumerator_next_element (objects_hash_enumerator_t *enumeratr,
const void **element);
/* Returns `false' if the enumeration is complete, `true' otherwise.
* If ELEMENT is non-zero, the next element of ENUMERATOR's hash table
* is returned by reference. */
int
objects_hash_enumerator_next_element(objects_hash_enumerator_t *enumerator,
const void **element);
/** Statistics **/
/** Statistics... **/
int objects_hash_is_empty (objects_hash_t * hash);
/* Returns `true' if HASH contains no elements. */
int
objects_hash_is_empty(objects_hash_t *hash);
size_t objects_hash_count (objects_hash_t * hash);
/* Returns the number of elements HASH is currently holding. So long as no
* additions or removals occur, you may take this number to be accurate. */
size_t
objects_hash_count(objects_hash_t *hash);
size_t objects_hash_capacity (objects_hash_t * hash);
/* Returns a number which represents (to some degree) HASH's current ability
* to hold stuff. Do not, however, rely on this for precision. Treat as
* a (reasonable) estimate. */
size_t
objects_hash_capacity(objects_hash_t *hash);
int objects_hash_check (objects_hash_t * hash);
/* Performs an internal consistency check on HASH. Useful only
* for debugging. */
int
objects_hash_check(objects_hash_t *hash);
/** Miscellaneous **/
/** Resizing... **/
size_t objects_hash_resize (objects_hash_t * hash, size_t new_capacity);
/* Resizes HASH to be ready to contain (at least) NEW_CAPACITY many elements.
* However, as far as you are concerned, it is indeterminate what exactly
* this means. After receiving and successfully processing this call,
* you are *not* guaranteed that HASH has actually set aside space for
* NEW_CAPACITY elements, for example. All that you are guaranteed is that,
* to the best of its ability, HASH will incur no loss in efficiency so long
* as it contains no more than NEW_CAPACITY elements. */
size_t
objects_hash_resize(objects_hash_t *hash, size_t new_capacity);
size_t objects_hash_rightsize (objects_hash_t * hash);
/* Shrinks (or grows) HASH to be comfortable with the number of elements
* it contains. In all likelyhood, after this call, HASH is more efficient
* in terms of its speed of search vs. use of space balance. */
size_t
objects_hash_rightsize(objects_hash_t *hash);
objects_hash_t * objects_hash_intersect_hash (objects_hash_t * hash, objects_hash_t * other_hash);
/** Describing... **/
objects_hash_t * objects_hash_minus_hash (objects_hash_t * hash, objects_hash_t * other_hash);
/* Returns a string describing (the contents of) HASH. */
NSString *
objects_hash_description(objects_hash_t *hash);
objects_hash_t * objects_hash_union_hash (objects_hash_t * hash, objects_hash_t * other_hash);
/** Set theoretic operations... **/
/* Removes from HASH all of its elements which are not also
* elements of OTHER_HASH. Returns HASH as a courtesy. */
objects_hash_t *
objects_hash_intersect_hash(objects_hash_t *hash, objects_hash_t *other_hash);
/* Removes from HASH all of its elements which are also
* elements of OTHER_HASH. Returns HASH as a courtesy. */
objects_hash_t *
objects_hash_minus_hash(objects_hash_t *hash, objects_hash_t *other_hash);
/* Adds to HASH all elements of OTHER_HASH which are not
* already members of HASH. Returns HASH as a courtesy. */
objects_hash_t *
objects_hash_union_hash(objects_hash_t *hash, objects_hash_t *other_hash);
#endif /* __hash_h_OBJECTS_INCLUDE */

View file

@ -1,10 +1,10 @@
/* A list for use with Libobjects.
/* A list structure.
* Copyright (C) 1995, 1996 Free Software Foundation, Inc.
*
* Author: Albin L. Jones <Albin.L.Jones@Dartmouth.EDU>
* Created: Tue Sep 5 17:25:59 EDT 1995
* Updated: Sat Feb 10 15:37:41 EST 1996
* Serial: 96.02.10.01
* Updated: Sun Mar 10 23:24:49 EST 1996
* Serial: 96.03.10.02
*
* This file is part of the GNU Objective C Class Library.
*
@ -20,16 +20,14 @@
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the Free
* Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*
*/
* Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
#ifndef __list_h_OBJECTS_INCLUDE
#define __list_h_OBJECTS_INCLUDE 1
/**** Included Headers *******************************************************/
#include <objects/allocs.h>
#include <Foundation/NSZone.h>
#include <objects/callbacks.h>
#include <objects/hash.h>
#include <objects/array.h>
@ -41,212 +39,308 @@ typedef struct _objects_list_node objects_list_node_t;
typedef struct _objects_list_enumerator objects_list_enumerator_t;
struct _objects_list_node
{
objects_list_t * list;
{
objects_list_t *list;
objects_list_node_t *next_in_list;
objects_list_node_t *prev_in_list;
objects_list_node_t *next_in_list;
objects_list_node_t *prev_in_list;
const void *element;
};
const void *element;
};
struct _objects_list
{
/* Container identifiers */
int magic;
size_t number;
char *name;
const void *extra;
objects_callbacks_t extra_callbacks;
objects_allocs_t allocs;
{
/* Container identifiers */
int magic_number;
size_t serial_number;
NSZone *zone;
NSString *name;
const void *extra;
objects_callbacks_t extra_callbacks;
/* Element callbacks */
objects_callbacks_t callbacks;
/* Element callbacks */
objects_callbacks_t callbacks;
/* Internal counters */
size_t node_count;
size_t element_count;
/* Internal counters */
size_t node_count;
size_t element_count;
/* Databanks */
objects_list_node_t *first_node;
objects_list_node_t *last_node;
};
/* Databanks */
objects_list_node_t *first_node;
objects_list_node_t *last_node;
};
struct _objects_list_enumerator
{
objects_list_t *list;
objects_list_node_t *node;
size_t forward;
};
{
objects_list_t *list;
objects_list_node_t *node;
size_t forward;
};
/**** Function Prototypes ****************************************************/
/** Basics **/
#include <objects/list-basics.h>
#include <objects/list-callbacks.h>
#include <objects/list-bas.h>
#include <objects/list-cbs.h>
/** Creating **/
objects_list_t * objects_list_alloc (void);
objects_list_t *
objects_list_alloc(void);
objects_list_t * objects_list_alloc_with_allocs (objects_allocs_t allocs);
objects_list_t *
objects_list_alloc_with_zone(NSZone *zone);
objects_list_t * objects_list_with_allocs (objects_allocs_t allocs);
objects_list_t *
objects_list_with_zone(NSZone *zone);
objects_list_t * objects_list_with_callbacks (objects_callbacks_t callbacks);
objects_list_t *
objects_list_with_callbacks(objects_callbacks_t callbacks);
objects_list_t * objects_list_with_allocs_with_callbacks (objects_allocs_t allocs, objects_callbacks_t callbacks);
objects_list_t *
objects_list_with_zone_with_callbacks(NSZone *zone,
objects_callbacks_t callbacks);
objects_list_t * objects_list_of_char_p (void);
objects_list_t *
objects_list_of_char_p(void);
objects_list_t * objects_list_of_void_p (void);
objects_list_t *
objects_list_of_non_owned_void_p(void);
objects_list_t * objects_list_of_owned_void_p (void);
objects_list_t *
objects_list_of_owned_void_p(void);
objects_list_t * objects_list_of_int (void);
objects_list_t *
objects_list_of_int(void);
objects_list_t * objects_list_of_int_p (void);
objects_list_t *
objects_list_of_int_p(void);
objects_list_t * objects_list_of_id (void);
objects_list_t *
objects_list_of_id(void);
/** Initializing **/
objects_list_t * objects_list_init (objects_list_t * list);
objects_list_t *
objects_list_init(objects_list_t *list);
objects_list_t * objects_list_init_with_callbacks (objects_list_t * list, objects_callbacks_t callbacks);
objects_list_t *
objects_list_init_with_callbacks(objects_list_t *list,
objects_callbacks_t callbacks);
/** Copying **/
objects_list_t * objects_list_copy (objects_list_t * old_list);
objects_list_t *
objects_list_copy(objects_list_t *old_list);
objects_list_t * objects_list_copy_with_allocs (objects_list_t * old_list, objects_allocs_t allocs);
objects_list_t *
objects_list_copy_with_zone(objects_list_t *old_list,
NSZone *zone);
/** Destroying **/
void objects_list_dealloc (objects_list_t * list);
void
objects_list_dealloc(objects_list_t *list);
/** Comparing **/
int objects_list_is_equal_to_list (objects_list_t * list, objects_list_t * other_list);
int
objects_list_is_equal_to_list(objects_list_t *list,
objects_list_t *other_list);
/** Concatenating **/
objects_list_t * objects_list_append_list (objects_list_t * base_list, objects_list_t * suffix_list);
objects_list_t *
objects_list_append_list(objects_list_t *base_list,
objects_list_t *suffix_list);
objects_list_t * objects_list_prepend_list (objects_list_t * base_list, objects_list_t * prefix_list);
objects_list_t *
objects_list_prepend_list(objects_list_t *base_list,
objects_list_t *prefix_list);
objects_list_t * objects_list_at_index_insert_list (objects_list_t * base_list, long int n, objects_list_t * infix_list);
objects_list_t *
objects_list_at_index_insert_list(objects_list_t *base_list,
long int n,
objects_list_t *infix_list);
/** Permuting **/
objects_list_t * objects_list_roll_to_nth_element (objects_list_t * list, long int n);
objects_list_t *
objects_list_roll_to_nth_element(objects_list_t *list, long int n);
objects_list_t * objects_list_roll_to_element (objects_list_t * list, const void *element);
objects_list_t *
objects_list_roll_to_element(objects_list_t *list, const void *element);
objects_list_t * objects_list_roll_to_nth_occurrance_of_element (objects_list_t * list, long int n, const void *element);
objects_list_t *
objects_list_roll_to_nth_occurrance_of_element(objects_list_t *list,
long int n,
const void *element);
objects_list_t * objects_list_invert (objects_list_t * list);
objects_list_t *
objects_list_invert(objects_list_t *list);
objects_list_t * objects_list_swap_elements_at_indices (objects_list_t * list, long int m, long int n);
objects_list_t *
objects_list_swap_elements_at_indices(objects_list_t *list,
long int m,
long int n);
/** Adding **/
const void *objects_list_append_element (objects_list_t * list, const void *element);
const void *
objects_list_append_element(objects_list_t *list, const void *element);
const void *objects_list_append_element_if_absent (objects_list_t * list, const void *element);
const void *
objects_list_append_element_if_absent(objects_list_t *list,
const void *element);
const void *objects_list_prepend_element (objects_list_t * list, const void *element);
const void *
objects_list_prepend_element(objects_list_t *list, const void *element);
const void *objects_list_prepend_element_if_absent (objects_list_t * list, const void *element);
const void *
objects_list_prepend_element_if_absent(objects_list_t *list,
const void *element);
const void *objects_list_at_index_insert_element (objects_list_t * list, long int n, const void *element);
const void *
objects_list_at_index_insert_element(objects_list_t *list,
long int n,
const void *element);
const void *objects_list_at_index_insert_element_if_absent (objects_list_t * list, long int n, const void *element);
const void *
objects_list_at_index_insert_element_if_absent(objects_list_t *list,
long int n,
const void *element);
const void *objects_list_queue_push_element (objects_list_t * list, const void *element);
const void *
objects_list_queue_push_element(objects_list_t *list, const void *element);
const void *objects_list_stack_push_element (objects_list_t * list, const void *element);
const void *
objects_list_stack_push_element(objects_list_t *list, const void *element);
/** Replacing **/
void objects_list_replace_nth_occurrance_of_element (objects_list_t * list, long int n, const void *old_element, const void *new_element);
void
objects_list_replace_nth_occurrance_of_element(objects_list_t *list,
long int n,
const void *old_element,
const void *new_element);
void objects_list_replace_element (objects_list_t * list, const void *old_element, const void *new_element);
void
objects_list_replace_element(objects_list_t *list,
const void *old_element,
const void *new_element);
void objects_list_replace_nth_element (objects_list_t * list, long int n, const void *new_element);
void
objects_list_replace_nth_element(objects_list_t *list,
long int n,
const void *new_element);
void objects_list_replace_first_element (objects_list_t * list, const void *new_element);
void
objects_list_replace_first_element(objects_list_t *list,
const void *new_element);
void objects_list_replace_last_element (objects_list_t * list, const void *new_element);
void
objects_list_replace_last_element(objects_list_t *list,
const void *new_element);
/** Removing **/
void objects_list_remove_nth_occurrence_of_element (objects_list_t * list, long int n, const void *element);
void
objects_list_remove_nth_occurrence_of_element(objects_list_t *list,
long int n,
const void *element);
void objects_list_remove_element (objects_list_t * list, const void *element);
void
objects_list_remove_element(objects_list_t *list, const void *element);
void objects_list_remove_nth_element (objects_list_t * list, long int n);
void
objects_list_remove_nth_element(objects_list_t *list, long int n);
void objects_list_remove_first_element (objects_list_t * list);
void
objects_list_remove_first_element(objects_list_t *list);
void objects_list_remove_last_element (objects_list_t * list);
void
objects_list_remove_last_element(objects_list_t *list);
void objects_list_queue_pop_element (objects_list_t * list);
void
objects_list_queue_pop_element(objects_list_t *list);
void objects_list_queue_pop_nth_element (objects_list_t * list, long int n);
void
objects_list_queue_pop_nth_element(objects_list_t *list, long int n);
void objects_list_stack_pop_element (objects_list_t * list);
void
objects_list_stack_pop_element(objects_list_t *list);
void objects_list_stack_pop_nth_element (objects_list_t * list, long int n);
void
objects_list_stack_pop_nth_element(objects_list_t *list, long int n);
/** Emptying **/
void objects_list_empty (objects_list_t * list);
void
objects_list_empty(objects_list_t *list);
/** Searching **/
int objects_list_contains_element (objects_list_t * list, const void *element);
int
objects_list_contains_element(objects_list_t *list, const void *element);
const void *objects_list_element (objects_list_t * list, const void *element);
const void *
objects_list_element(objects_list_t *list, const void *element);
const void *objects_list_nth_element (objects_list_t * list, long int n);
const void *
objects_list_nth_element(objects_list_t *list, long int n);
const void *objects_list_first_element (objects_list_t * list);
const void *
objects_list_first_element(objects_list_t *list);
const void *objects_list_last_element (objects_list_t * list);
const void *
objects_list_last_element(objects_list_t *list);
const void **objects_list_all_elements (objects_list_t * list);
const void **
objects_list_all_elements(objects_list_t *list);
/** Enumerating **/
objects_list_enumerator_t objects_list_enumerator (objects_list_t * list);
objects_list_enumerator_t
objects_list_enumerator(objects_list_t *list);
objects_list_enumerator_t objects_list_forward_enumerator (objects_list_t * list);
objects_list_enumerator_t
objects_list_forward_enumerator(objects_list_t *list);
objects_list_enumerator_t objects_list_reverse_enumerator (objects_list_t * list);
objects_list_enumerator_t
objects_list_reverse_enumerator(objects_list_t *list);
int objects_list_enumerator_next_element (objects_list_enumerator_t *enumerator, const void **element);
int
objects_list_enumerator_next_element(objects_list_enumerator_t *enumerator,
const void **element);
/** Mapping **/
/* NO WARNING: The mapping function FCN need not be one-to-one on the
* elements of LIST. In fact, FCN may do whatever it likes. */
objects_list_t * objects_list_map_elements (objects_list_t * list, const void *(*fcn) (const void *, const void *), const void *user_data);
objects_list_t *
objects_list_map_elements(objects_list_t *list,
const void *(*fcn)(const void *, void *),
void *user_data);
/** Statistics **/
int objects_list_is_empty (objects_list_t * list);
int
objects_list_is_empty(objects_list_t *list);
size_t objects_list_count (objects_list_t * list);
size_t
objects_list_count(objects_list_t *list);
size_t objects_list_capacity (objects_list_t * list);
size_t
objects_list_capacity(objects_list_t *list);
int objects_list_check (objects_list_t * list);
int
objects_list_check(objects_list_t *list);
/** Miscellaneous **/
objects_hash_t *objects_hash_init_from_list (objects_hash_t *hash, objects_list_t * list);
objects_hash_t *
objects_hash_init_from_list(objects_hash_t *hash, objects_list_t *list);
#endif /* __list_h_OBJECTS_INCLUDE */

View file

@ -1,10 +1,10 @@
/* A map table for use with Libobjects.
/* A map table.
* Copyright (C) 1993, 1994, 1995, 1996 Free Software Foundation, Inc.
*
* Author: Albin L. Jones <Albin.L.Jones@Dartmouth.EDU>
* Created: ??? ??? ?? ??:??:?? ??? 1993
* Updated: Sat Feb 10 13:36:59 EST 1996
* Serial: 96.02.10.01
* Updated: Thu Mar 21 00:05:43 EST 1996
* Serial: 96.03.20.04
*
* This file is part of the GNU Objective C Class Library.
*
@ -20,21 +20,20 @@
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the Free
* Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*
*/
* Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
#ifndef __map_h_OBJECTS_INCLUDE
#define __map_h_OBJECTS_INCLUDE 1
/**** Included Headers *******************************************************/
#include <objects/allocs.h>
#include <Foundation/NSZone.h>
#include <objects/callbacks.h>
#include <objects/hash.h>
/**** Type, Constant, and Macro Definitions **********************************/
/* Need these up here because of their interdependence. */
typedef struct _objects_map objects_map_t;
typedef struct _objects_map_bucket objects_map_bucket_t;
typedef struct _objects_map_node objects_map_node_t;
@ -42,40 +41,56 @@ typedef struct _objects_map_enumerator objects_map_enumerator_t;
/* Important structures... */
/* Private type for elemental holding. */
struct _objects_map_node
{
const void *key;
const void *value;
objects_map_bucket_t *bucket;
/* The map table with which the node is associated. */
objects_map_t *map;
/* The bucket in MAP in which the node sits. */
objects_map_bucket_t *bucket;
/* These hold the BUCKET linked list together. */
objects_map_node_t *next_in_bucket;
objects_map_node_t *prev_in_bucket;
/* For enumerating over the whole map table. These make
* enumerating much quicker. They also make it safer. */
objects_map_node_t *next_in_map;
objects_map_node_t *prev_in_map;
const void *key;
const void *value;
};
/* Private type for holding chains of nodes. */
struct _objects_map_bucket
{
/* The number of nodes in this bucket. For internal consistency checks. */
size_t node_count;
/* The number of elements in this bucket. (This had *better* be
* the same as NODE_COUNT, or something's wrong.) */
size_t element_count;
/* The head of this bucket's linked list of nodes. */
objects_map_node_t *first_node;
};
/* The map table type. */
struct _objects_map
{
/* Container identifiers */
int magic;
size_t number;
char *name;
/* All structures have these...
* And all structures have them in the same order. */
int magic_number;
size_t serial_number;
NSZone *zone;
NSString *name;
const void *extra;
objects_callbacks_t extra_callbacks;
objects_allocs_t allocs;
objects_callbacks_t key_callbacks;
/* Management information */
/* For keys...And Values. */
objects_callbacks_t key_callbacks;
objects_callbacks_t value_callbacks;
/* Internal counters */
@ -83,248 +98,332 @@ struct _objects_map
size_t node_count;
size_t element_count;
/* Databanks */
objects_map_bucket_t *buckets;
objects_map_node_t *first_node;
/* Places to start looking for elements. */
objects_map_bucket_t *buckets; /* Organized as a hash. */
objects_map_node_t *first_node; /* Organized as a linked list.
* (For enumerating...) */
};
/* Type for enumerating the elements of a map table. */
struct _objects_map_enumerator
{
objects_map_t *map;
objects_map_node_t *node;
objects_map_t *map; /* To which hash do I belong? */
objects_map_node_t *node; /* Which node is next? */
};
/**** Function Prototypes ****************************************************/
/** Basics **/
/** Basics... **/
#include <objects/map-basics.h>
#include <objects/map-callbacks.h>
/* All the structures (hashes, maps, lists, and arrays) have
* the same basic ideas behind them. */
/** Altering capacity **/
#include <objects/map-bas.h>
#include <objects/map-cbs.h>
size_t
objects_map_resize (objects_map_t * map, size_t new_capacity);
/** Callbacks... **/
size_t
objects_map_rightsize (objects_map_t * map);
/* Returns a collection of callbacks for use with hash tables. */
objects_callbacks_t
objects_callbacks_for_map(void);
/** Creating **/
/** Creating... **/
/* Allocate a hash table in the default zone. */
objects_map_t *
objects_map_alloc(void);
/* Allocate a hash table in the memory block ZONE. */
objects_map_t *
objects_map_alloc_with_zone(NSZone *zone);
/* Create an empty map table in the memory block ZONE. The returned
* hash table has a "reasonable" default capacity, but will need to
* be resized to suit your specific needs if more than a couple of
* dozen key/value pairs will be placed within it. */
objects_map_t *
objects_map_with_zone_with_callbacks(NSZone *zone,
objects_callbacks_t key_callbacks,
objects_callbacks_t value_callbacks);
/* Like calling 'objects_map_with_zone_with_callbacks(0, key_callbacks,
* value_callbacks)'. */
objects_map_t *
objects_map_with_callbacks(objects_callbacks_t key_callbacks,
objects_callbacks_t value_callbacks);
/* Like calling 'objects_map_with_zone_with_callbacks(0,
* objects_callbacks_standard(), objects_callbacks_standard())'. */
objects_map_t *
objects_map_with_zone(NSZone *zone);
/* Shortcuts... */
objects_map_t *objects_map_of_int(void);
objects_map_t *objects_map_of_int_to_char_p(void);
objects_map_t *objects_map_of_int_to_non_owned_void_p(void);
objects_map_t *objects_map_of_int_to_id(void);
objects_map_t *objects_map_of_char_p(void);
objects_map_t *objects_map_of_char_p_to_int(void);
objects_map_t *objects_map_of_char_p_to_non_owned_void_p(void);
objects_map_t *objects_map_of_char_p_to_id(void);
objects_map_t *objects_map_of_non_owned_void_p(void);
objects_map_t *objects_map_of_non_owned_void_p_to_int(void);
objects_map_t *objects_map_of_non_owned_void_p_to_char_p(void);
objects_map_t *objects_map_of_non_owned_void_p_to_id(void);
objects_map_t *objects_map_of_id(void);
/** Initializing... **/
objects_map_t *
objects_map_alloc (void);
objects_map_init(objects_map_t *map);
objects_map_t *
objects_map_alloc_with_allocs (objects_allocs_t allocs);
objects_map_init_with_callbacks(objects_map_t *map,
objects_callbacks_t key_callbacks,
objects_callbacks_t value_callbacks);
objects_map_t *
objects_map (void);
object_map_init_from_map(objects_map_t *map, objects_map_t *old_map);
objects_map_t *
objects_map_with_allocs (objects_allocs_t allocs);
objects_map_t *
objects_map_with_allocs_with_callbacks (objects_allocs_t allocs,
objects_callbacks_t key_callbacks,
objects_callbacks_t value_callbacks);
objects_map_t *
objects_map_with_callbacks (objects_callbacks_t key_callbacks,
objects_callbacks_t value_callbacks);
objects_map_t *
objects_map_of_int (void);
objects_map_t *
objects_map_of_int_to_char_p (void);
objects_map_t *
objects_map_of_int_to_void_p (void);
objects_map_t *
objects_map_of_int_to_float (void);
objects_map_t *
objects_map_of_char_p (void);
objects_map_t *
objects_map_of_char_p_to_int (void);
objects_map_t *
objects_map_of_char_p_to_void_p (void);
objects_map_t *
objects_map_of_char_p_to_float (void);
objects_map_t *
objects_map_of_void_p (void);
objects_map_t *
objects_map_of_void_p_to_int (void);
objects_map_t *
objects_map_of_void_p_to_char_p (void);
objects_map_t *
objects_map_of_void_p_to_float (void);
objects_map_t *
objects_map_of_float (void);
objects_map_t *
objects_map_of_double (void);
/** Initializing **/
objects_map_t *
objects_map_init (objects_map_t * map);
objects_map_t *
objects_map_init_with_callbacks (objects_map_t * map,
objects_callbacks_t key_callbacks,
objects_callbacks_t value_callbacks);
/** Destroying **/
/** Destroying... **/
/* Releases all the keys and values of MAP, and then
* deallocates MAP itself. */
void
objects_map_dealloc (objects_map_t * map);
objects_map_dealloc(objects_map_t *map);
/** Gathering statistics on a mapionary **/
/** Gathering statistics on a map... **/
/* Returns the number of key/value pairs in MAP. */
size_t
objects_map_pair_count (objects_map_t * map);
objects_map_count(objects_map_t *map);
/* Returns some (inexact) measure of how many key/value pairs
* MAP can comfortably hold without resizing. */
size_t
objects_map_capacity (objects_map_t * map);
objects_map_capacity(objects_map_t *map);
/* Performs an internal consistency check, returns 'true' if
* everything is OK, 'false' otherwise. Really useful only
* for debugging. */
int
objects_map_check_map (objects_map_t * map);
objects_map_check(objects_map_t *map);
/** Finding elements in a mapionary **/
/** Finding elements in a map... **/
/* Returns 'true' if and only if some key in MAP is equal
* (in the sense of the key callbacks of MAP) to KEY. */
int
objects_map_contains_key (objects_map_t * map, const void *key);
objects_map_contains_key(objects_map_t *map, const void *key);
/* Returns 'true' if and only if some value in MAP is equal
* (in the sense of the value callbacks of MAP) to VALUE. */
/* WARNING: This is rather inefficient. Not to be used lightly. */
int
objects_map_key_and_value (objects_map_t * map,
const void *key,
void **old_key,
void **value);
objects_map_contains_value(objects_map_t *map, const void *value);
/* If KEY is in MAP, then the following three things happen:
* (1) 'true' is returned;
* (2) if OLD_KEY is non-zero, then the key in MAP
* equal to KEY is placed there;
* (3) if VALUE is non-zero, then the value in MAP
* mapped to by KEY is placed there.
* If KEY is not in MAP, then the following three things happen:
* (1) 'false' is returned;
* (2) if OLD_KEY is non-zero, then the "not a key marker"
* for MAP is placed there;
* (3) if VALUE is non-zero, then the the "not a value marker"
* for MAP is placed there. */
int
objects_map_key_and_value_at_key(objects_map_t *map,
const void **old_key,
const void **value,
const void *key);
/* If KEY is in MAP, then the key of MAP which is equal to KEY
* is returned. Otherwise, the "not a key marker" for MAP is returned. */
const void *
objects_map_key (objects_map_t * map, const void *key);
objects_map_key_at_key(objects_map_t *map, const void *key);
/* If KEY is in MAP, then the value of MAP which to which KEY maps
* is returned. Otherwise, the "not a value marker" for MAP is returned. */
const void *
objects_map_value_at_key (objects_map_t * map, const void *key);
objects_map_value_at_key(objects_map_t *map, const void *key);
/** Enumerating the nodes and elements of a mapionary **/
/** Enumerating the nodes and elements of a map... **/
objects_map_enumerator_t
objects_map_enumerator (objects_map_t * map);
objects_map_enumerator_for_map(objects_map_t *map);
int
objects_map_enumerator_next_key_and_value (objects_map_enumerator_t *enumeratr,
const void **key,
const void **value);
objects_map_enumerator_next_key_and_value(objects_map_enumerator_t *enumerator,
const void **key,
const void **value);
int
objects_map_enumerator_next_key (objects_map_enumerator_t * enumerator,
const void **key);
objects_map_enumerator_next_key(objects_map_enumerator_t *enumerator,
const void **key);
int
objects_map_enumerator_next_value (objects_map_enumerator_t * enumerator,
const void **value);
objects_map_enumerator_next_value(objects_map_enumerator_t *enumerator,
const void **value);
/** Obtaining an array of the elements of a mapionary **/
/** Obtaining an array of the elements of a map... **/
const void **
objects_map_all_keys_and_values (objects_map_t * map);
objects_map_all_keys_and_values(objects_map_t *map);
const void **
objects_map_all_keys (objects_map_t * map);
objects_map_all_keys(objects_map_t *map);
const void **
objects_map_all_values (objects_map_t * map);
objects_map_all_values(objects_map_t *map);
/** Removing **/
/** Removing... **/
/* Removes the key/value pair (if any) from MAP whose key is KEY. */
void
objects_map_remove_key (objects_map_t * map, const void *key);
objects_map_remove_key(objects_map_t *map, const void *key);
/* Releases all of the keys and values of MAP without
* altering MAP's capacity. */
void
objects_map_empty (objects_map_t * map);
objects_map_empty(objects_map_t *map);
/** Adding **/
/** Adding... **/
const void *
objects_map_at_key_put_value_known_absent (objects_map_t * map,
const void *key,
const void *value);
objects_map_at_key_put_value_known_absent(objects_map_t *map,
const void *key,
const void *value);
const void *
objects_map_at_key_put_value (objects_map_t * map,
const void *key,
const void *value);
objects_map_at_key_put_value(objects_map_t *map,
const void *key,
const void *value);
const void *
objects_map_at_key_put_value_if_absent (objects_map_t * map,
const void *key,
const void *value);
objects_map_at_key_put_value_if_absent(objects_map_t *map,
const void *key,
const void *value);
/** Replacing **/
/** Replacing... **/
void
objects_map_replace_key (objects_map_t * map, const void *key);
objects_map_replace_key(objects_map_t *map, const void *key);
/** Comparing **/
/** Comparing... **/
/* Returns 'true' if every key/value pair of MAP2 is also a key/value pair
* of MAP1. Otherwise, returns 'false'. */
int
objects_map_contains_map (objects_map_t * map1, objects_map_t * map2);
objects_map_contains_map(objects_map_t *map1, objects_map_t *map2);
/* Returns 'true' if MAP1 and MAP2 have the same number of key/value pairs,
* MAP1 contains MAP2, and MAP2 contains MAP1. Otherwise, returns 'false'. */
int
objects_map_is_equal_to_map (objects_map_t * map1, objects_map_t * map2);
objects_map_is_equal_to_map(objects_map_t *map1, objects_map_t *map2);
/** Copying **/
/* Returns 'true' iff every key of MAP2 is a key of MAP1. */
int
objects_map_keys_contain_keys_of_map(objects_map_t *map1, objects_map_t *map2);
/* Returns 'true' if MAP1 and MAP2 have the same number of key/value pairs,
* MAP1 contains every key of MAP2, and MAP2 contains every key of MAP1.
* Otherwise, returns 'false'. */
int
objects_map_keys_are_equal_to_keys_of_map(objects_map_t *map1,
objects_map_t *map2);
/* Returns 'true' iff some key/value pair of MAP1 if also
* a key/value pair of MAP2. */
int
objects_map_intersects_map(objects_map_t *map1, objects_map_t *map2);
/* Returns 'true' iff some key of MAP1 if also a key of MAP2. */
int
objects_map_keys_intersect_keys_of_map(objects_map_t *map1,
objects_map_t *map2);
/** Copying... **/
/* Returns a copy of OLD_MAP in ZONE. Remember that, as far as what
* (if anything) OLD_MAP's keys and values point to, this copy is
* shallow. If, for example, OLD_MAP is a map from int to int, then
* you've got nothing more to worry about. If, however, OLD_MAP is a
* map from id to id, and you want the copy of OLD_MAP to be "deep",
* you'll need to use the mapping functions below to make copies of
* all of the returned map's elements. */
objects_map_t *
objects_map_copy_with_allocs (objects_map_t * old_map, objects_allocs_t new_allocs);
objects_map_copy_with_zone(objects_map_t *old_map, NSZone *zone);
/* Just like 'objects_map_copy_with_zone()', but returns a copy of
* OLD_MAP in the default zone. */
objects_map_t *
objects_map_copy (objects_map_t * old_map);
objects_map_copy(objects_map_t *old_map);
/** Mapping **/
/** Mapping... **/
/* WARNING: The mapping function KFCN must be one-to-one on the keys
* of MAP. I.e., `objects_map_map_keys()' makes no provision for the
* possibility that KFCN maps two unequal keys of MAP to the same (or
* equal) keys. */
/* Iterates through MAP, replacing each key with the result of
* '(*kfcn)(key, user_data)'. Useful for deepening copied maps
* and other uniform (and one-to-one) transformations of map keys. */
/* WARNING: The mapping function KFCN *must* be one-to-one on the
* (equivalence classes of) keys of MAP. I.e., for efficiency's sake,
* `objects_map_map_keys()' makes no provision for the possibility
* that KFCN maps two unequal keys of MAP to the same (or equal) keys. */
objects_map_t *
objects_map_map_keys (objects_map_t * map,
const void *(*kfcn) (const void *, const void *),
const void *user_data);
objects_map_map_keys(objects_map_t *map,
const void *(*kfcn)(const void *, void *),
void *user_data);
/* Iterates through MAP, replacing each value with the result of
* '(*vfcn)(value, user_data)'. Useful for deepening copied maps
* and other uniform transformations of map keys. */
/* NO WARNING: The mapping function VFCN need not be one-to-one on
* (the equivalence classes of) values. */
objects_map_t *
objects_map_map_values (objects_map_t * map,
const void *(*vfcn) (const void *, const void *),
const void *user_data);
objects_map_map_values(objects_map_t *map,
const void *(*vfcn)(const void *, void *),
void *user_data);
/** Miscellaneous **/
/** Resizing... **/
/* Resizes MAP to be ready to contain (at least) NEW_CAPACITY many elements.
* However, as far as you are concerned, it is indeterminate what exactly
* this means. After receiving and successfully processing this call,
* you are *not* guaranteed that MAP has actually set aside space for
* NEW_CAPACITY elements, for example. All that you are guaranteed is that,
* to the best of its ability, MAP will incur no loss in efficiency so long
* as it contains no more than NEW_CAPACITY elements. */
size_t
objects_map_resize(objects_map_t *map, size_t new_capacity);
/* Shrinks (or grows) MAP to be comfortable with the number of elements
* it contains. In all likelyhood, after this call, MAP is more efficient
* in terms of its speed of search vs. use of space balance. */
size_t
objects_map_rightsize(objects_map_t *map);
/** Describing... **/
/* Returns a string describing (the contents of) MAP. */
NSString *
objects_map_description(objects_map_t *map);
/** Set theoretic operations... **/
objects_map_t *
objects_map_intersect_map (objects_map_t * map, objects_map_t * other_map);
objects_map_intersect_map(objects_map_t *map, objects_map_t *other_map);
objects_map_t *
objects_map_minus_map (objects_map_t * map, objects_map_t * other_map);
objects_map_minus_map(objects_map_t *map, objects_map_t *other_map);
objects_map_t *
objects_map_union_map (objects_map_t * map, objects_map_t * other_map);
objects_map_union_map(objects_map_t *map, objects_map_t *other_map);
objects_hash_t *
objects_hash_init_from_map_keys (objects_hash_t * hash, objects_map_t * map);
objects_hash_init_from_map_keys(objects_hash_t *hash, objects_map_t *map);
objects_hash_t *
objects_hash_init_from_map_values (objects_hash_t * hash, objects_map_t * map);
objects_hash_init_from_map_values(objects_hash_t *hash, objects_map_t *map);
#endif /* __map_h_OBJECTS_INCLUDE */

View file

@ -1,111 +0,0 @@
/* Basic functions for @XX@ structures.
* Copyright (C) 1995, 1996 Free Software Foundation, Inc.
*
* Author: Albin L. Jones <Albin.L.Jones@Dartmouth.EDU>
* Created: Mon Dec 11 01:24:48 EST 1995
* Updated: Sat Feb 10 09:56:21 EST 1996
* Serial: 96.02.10.01
*
* This file is part of the GNU Objective C Class Library.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the Free
* Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*
*/
#ifndef __@XX@_xx_h_OBJECTS_INCLUDE
#define __@XX@_xx_h_OBJECTS_INCLUDE 1
/**** Included Headers *******************************************************/
#include <stdlib.h>
#include <objects/allocs.h>
#include <objects/number.h>
#include <objects/magic.h>
/**** Type, Constant, and Macro Definitions **********************************/
#define __@XX@__ 1
/**** Function Implementations ***********************************************/
/** Magic **/
/* Returns XX's magic number. */
int objects_@XX@_magic (objects_@XX@_t *xx);
/** Allocs **/
/* Returns the allocs used to create and maintain XX. */
objects_allocs_t objects_@XX@_allocs (objects_@XX@_t *xx);
/** Names **/
/* Returns the name that was given to XX. */
const char *objects_@XX@_name (objects_@XX@_t *xx);
/* Gives XX a name. Space is allocated, and the contents of the
* NUL-terminated NAME are copied. Deallocating XX frees up the
* space. I.e., it is not the responsibility of the programmer to
* keep track of space allocated for this procedure. */
const char *objects_@XX@_set_name (objects_@XX@_t *xx, const char *name);
/* Takes away XX's name. */
void objects_@XX@_unset_name (objects_@XX@_t *xx);
/** Number **/
/* Returns the (process-wide) unique number given to the Libfn
* structure XX. See <objects/number.h> for more info. */
size_t objects_@XX@_serial_number (objects_@XX@_t *xx);
/* Gives XX a new (process-wide) unique number. Numbers are not
* reused. See <objects/number.h> for more info. */
size_t _objects_@XX@_set_serial_number (objects_@XX@_t *xx);
/** Extras **/
/* Sets the callbacks associated with XX's ``extra''. NOTE: This must
* be done before calling `objects_@XX@_set_extra()', as these callbacks
* are used in that routine. */
objects_callbacks_t objects_@XX@_set_extra_callbacks (objects_@XX@_t *xx, objects_callbacks_t callbacks);
/* Returns the callbacks associated with XX's ``extra''. */
objects_callbacks_t objects_@XX@_extra_callbacks (objects_@XX@_t *xx, objects_callbacks_t callbacks);
/* Returns XX's ``extra'', a little extra space that each Libobjects
* structure carries around with it. Its use is
* implementation-dependent. */
const void *objects_@XX@_extra (objects_@XX@_t *xx);
/* Sets XX's ``extra'', a little extra space that each Libobjets structure
* carries around with it. Its use is implementation-dependent. */
const void *objects_@XX@_set_extra (objects_@XX@_t *xx, const void *extra);
/* Resets XX's ``extra''. */
void objects_@XX@_unset_extra (objects_@XX@_t *xx);
/** Low-level Creation and Destruction **/
/* Handles the universal, low-level allocation of Libobjects structures. */
objects_@XX@_t *_objects_@XX@_alloc_with_allocs (objects_allocs_t allocs);
/* Handles the universal, low-level deallocation of Libobjects structures. */
void _objects_@XX@_dealloc (objects_@XX@_t *xx);
/* Handles the low-level copying of Libobjects structures. */
objects_@XX@_t *_objects_@XX@_copy_with_allocs (objects_@XX@_t *xx, objects_allocs_t allocs);
#endif /* __@XX@_xx_h_OBJECTS_INCLUDE */

View file

@ -1,71 +0,0 @@
/* Getting callbacks from @YY@ structures.
* Copyright (C) 1995, 1996 Free Software Foundation, Inc.
*
* Author: Albin L. Jones <Albin.L.Jones@Dartmouth.EDU>
* Created: Mon Dec 11 03:41:00 EST 1995
* Updated: Sat Feb 10 10:21:13 EST 1996
* Serial: 96.02.10.01
*
* This file is part of the GNU Objective C Class Library.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the Free
* Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*
*/
#ifndef __@YY@_yy_h_OBJECTS_INCLUDE
#define __@YY@_yy_h_OBJECTS_INCLUDE 1
/**** Included Headers *******************************************************/
#include <objects/callbacks.h>
#include <objects/@YY@.h>
/**** Type, Constant, and Macro Definitions **********************************/
#define __@YY@__ 1
/**** Function Implementations ***********************************************/
#ifdef __map__
/** Callbacks **/
/* Returns the callbacks associated with YY's keys. */
objects_callbacks_t objects_@YY@_key_callbacks (objects_@YY@_t *yy);
/* Returns the ``bogus'' marker associated with YY's keys. */
const void *objects_@YY@_not_a_key_marker (objects_@YY@_t *yy);
/* Returns the callbacks associated with YY's values. */
objects_callbacks_t
objects_@YY@_value_callbacks (objects_@YY@_t *yy);
/* Returns the ``bogus'' marker associated with YY's values. */
const void *objects_@YY@_not_a_value_marker (objects_@YY@_t *yy);
#else /* !__map__ */
/** Callbacks **/
/* Returns the callbacks associated with YY's elements. */
objects_callbacks_t objects_@YY@_element_callbacks (objects_@YY@_t *yy);
/* Returns the ``bogus'' marker associated with YY's elements. */
const void *objects_@YY@_not_an_element_marker (objects_@YY@_t *yy);
#endif /* __map__ */
#endif /* __@YY@_yy_h_OBJECTS_INCLUDE */

View file

@ -165,67 +165,43 @@ String.m \
TcpPort.m \
TextCStream.m \
UdpPort.m \
atoz.m \
callbacks-id.m \
array.m \
array-bas.m \
array-cbs.m \
callbacks.m \
cbs-char-p.m \
cbs-id.m \
cbs-int.m \
cbs-int-p.m \
cbs-void-p.m \
hash.m \
hash-bas.m \
hash-cbs.m \
list.m \
list-bas.m \
list-cbs.m \
map.m \
map-bas.m \
map-cbs.m \
stdobjects.m \
mframe.m \
objc-gnu2next.m
GNU_CFILES = \
abort.c \
allocs.c \
array.c \
behavior.c \
callbacks.c \
callbacks-char_p.c \
callbacks-int.c \
callbacks-int_p.c \
callbacks-void_p.c \
data.c \
hash.c \
list.c \
map.c \
md5.c \
number.c \
numbers.c \
objc-malloc.c \
o_vscanf.c
GNU_BASICS_CFILES = \
array-basics.c \
data-basics.c \
hash-basics.c \
list-basics.c \
map-basics.c
GNU_BASICS_HFILES = \
objects/array-basics.h \
objects/data-basics.h \
objects/hash-basics.h \
objects/list-basics.h \
objects/map-basics.h
GNU_CALLBACKS_CFILES = \
array-callbacks.c \
hash-callbacks.c \
list-callbacks.c \
map-callbacks.c
GNU_CALLBACKS_HFILES = \
objects/array-callbacks.h \
objects/hash-callbacks.h \
objects/list-callbacks.h \
objects/map-callbacks.h
GNU_OTHER_SRCFILES = \
x-basics.c.in \
x-callbacks.c.in \
objects/x-basics.h.in \
objects/x-callbacks.h.in \
x-bas.m.in \
x-cbs.m.in \
objects/x-bas.h.in \
objects/x-cbs.h.in \
md5.h
GNU_OBJS = \
$(GNU_BASICS_CFILES:.c=$(OEXT)) \
$(GNU_CALLBACKS_CFILES:.c=$(OEXT)) \
$(GNU_MFILES:.m=$(OEXT)) \
$(GNU_CFILES:.c=$(OEXT))
@ -308,20 +284,22 @@ objects/TextCStream.h \
objects/Time.h \
objects/UdpPort.h \
objects/ValueHolding.h \
objects/abort.h \
objects/allocs.h \
objects/array.h \
objects/array-bas.h \
objects/array-cbs.h \
objects/behavior.h \
objects/bitops.h \
objects/callbacks.h \
objects/data.h \
objects/hash.h \
objects/hash-bas.h \
objects/hash-cbs.h \
objects/list.h \
objects/magic.h \
objects/list-bas.h \
objects/list-cbs.h \
objects/map.h \
objects/map-bas.h \
objects/map-cbs.h \
objects/mframe.h \
objects/minmax.h \
objects/number.h \
objects/numbers.h \
objects/objc-gnu2next.h \
objects/objc-malloc.h \
objects/objects.h \
@ -472,11 +450,9 @@ Foundation/NSTimer.h \
Foundation/NSUtilities.h \
Foundation/NSValue.h \
Foundation/NSZone.h \
Foundation/atoz.h \
Foundation/objc-load.h
HEADERS_INSTALL = @HEADERS_INSTALL@ \
$(GNU_BASICS_HFILES) $(GNU_CALLBACKS_HFILES) \
objects/stdobjects.h
OBJS_INSTALL = @OBJS_INSTALL@
OBJS_INSTALL_PIC = $(OBJS_INSTALL:$(OEXT)=_pic$(OEXT))
@ -516,7 +492,7 @@ RCS_FILES = \
all: libobjects$(LIBEXT) @LIBOBJECTS_SO@
libobjects.so.$(OBJECTS_VERSION): objects/stdobjects.h $(OBJS_INSTALL_PIC)
libobjects.so.$(OBJECTS_VERSION): $(HEADERS_INSTALL) $(OBJS_INSTALL_PIC)
$(CC) -shared -o libobjects.so.$(OBJECTS_VERSION) \
-Wl,-soname,libobjects.so.$(OBJECTS_MAJOR_VERSION) \
$(OBJS_INSTALL_PIC)
@ -527,7 +503,7 @@ libobjects.so.$(OBJECTS_VERSION): objects/stdobjects.h $(OBJS_INSTALL_PIC)
ln -s libobjects.so.$(OBJECTS_MAJOR_VERSION) \
libobjects.so
libobjects$(LIBEXT): objects/stdobjects.h $(OBJS_INSTALL)
libobjects$(LIBEXT): $(HEADERS_INSTALL) $(OBJS_INSTALL)
$(AR) $(ARFLAGS) $(AROUT)libobjects$(LIBEXT) $(OBJS_INSTALL)
$(RANLIB) libobjects$(LIBEXT)
@ -601,30 +577,28 @@ objects/stdobjects.h: $(srcdir)/../Version $(srcdir)/objects/stdobjects.h.in
> $(srcdir)/objects/stdobjects.h
stdobjects$(OEXT): objects/stdobjects.h
# The Xs and Ys...
# The Xs and Ys...Don't mess with these without thinking first.
objects/%-basics.h: objects/x-basics.h.in
sed -e "s/@XX@/$*/g" $^ > $@
objects/%-bas.h: objects/x-bas.h.in
sed -e "s/@XX@/$*/g" $< > $@
objects/%-callbacks.h: objects/x-callbacks.h.in
sed -e "s/@YY@/$*/g" $^ > $@
objects/%-cbs.h: objects/x-cbs.h.in
sed -e "s/@YY@/$*/g" $< > $@
%-basics.c: x-basics.c.in objects/%.h
sed -e "s/@XX@/$*/g" $^ > $@
%-bas.m: x-bas.m.in objects/%.h
sed -e "s/@XX@/$*/g" $< > $@
%-callbacks.c: x-callbacks.c.in objects/%.h
sed -e "s/@YY@/$*/g" $^ > $@
%-cbs.m: x-cbs.m.in objects/%.h
sed -e "s/@YY@/$*/g" $< > $@
array.o: array.c objects/array.h
objects/array.h: objects/array-basics.h objects/array-callbacks.h objects/hash.h
data.o: data.c objects/data.h
objects/data.h: objects/data-basics.h
hash.o: hash.c objects/hash.h
objects/hash.h: objects/hash-basics.h objects/hash-callbacks.h
list.o: list.c objects/list.h
objects/list.h: objects/list-basics.h objects/list-callbacks.h objects/hash.h
map.o: map.c objects/map.h
objects/map.h: objects/map-basics.h objects/map-callbacks.h objects/hash.h
array.o: array.m objects/array.h
objects/array.h: objects/array-bas.h objects/array-cbs.h objects/hash.h
hash.o: hash.m objects/hash.h
objects/hash.h: objects/hash-bas.h objects/hash-cbs.h
list.o: list.m objects/list.h
objects/list.h: objects/list-bas.h objects/list-cbs.h objects/array.h objects/hash.h
map.o: map.m objects/map.h
objects/map.h: objects/map-bas.h objects/map-cbs.h objects/hash.h
Makefile: $(srcdir)/Makefile.in ../config.status
@ -657,8 +631,6 @@ mostlyclean:
clean: mostlyclean
rm -f libobjects$(LIBEXT) *$(OEXT)
rm -f $(NSVALUE_MFILES) $(NSNUMBER_MFILES)
rm -f $(GNU_BASICS_CFILES) $(GNU_CALLBACKS_CFILES)
rm -f $(GNU_BASICS_HFILES) $(GNU_CALLBACKS_HFILES)
distclean: clean
rm -f Makefile
rm -f dynamic-load.h

View file

@ -20,9 +20,7 @@
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the Free
* Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*
*/
* Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
#ifndef __NSCallBacks_h_OBJECTS_INCLUDE
#define __NSCallBacks_h_OBJECTS_INCLUDE 1

View file

@ -3,8 +3,8 @@
*
* Author: Albin L. Jones <Albin.L.Jones@Dartmouth.EDU>
* Created: Tue Feb 13 23:10:29 EST 1996
* Updated: Tue Feb 13 23:10:29 EST 1996
* Serial: 96.02.13.01
* Updated: Wed Mar 20 19:53:48 EST 1996
* Serial: 96.03.20.02
*
* This file is part of the GNU Objective C Class Library.
*
@ -20,9 +20,7 @@
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the Free
* Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*
*/
* Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
/**** Included Headers *******************************************************/
@ -98,12 +96,11 @@ _NS_owned_void_p_release (void *table, void *p)
NSString *
_NS_owned_void_p_describe (void *table, void *p)
{
/* This may not be right; I'm doing this off of the top of my head, and
* I'm in a hurry. */
return [NSString stringWithFormat:@"%0x", p];
return [NSString stringWithFormat:@"%#x", p];
}
/** For non-retained Objective-C objects **/
unsigned int
_NS_non_retained_id_hash (void *table, id <NSObject> o)
{
@ -113,8 +110,6 @@ _NS_non_retained_id_hash (void *table, id <NSObject> o)
BOOL
_NS_non_retained_id_is_equal (void *table, id <NSObject> o, id <NSObject> p)
{
/* Once again I need a nice way to determine whether or not O
* responds to `isEqual:'. */
return [o isEqual:p];
}
@ -133,16 +128,14 @@ _NS_non_retained_id_release (void *table, id <NSObject> o)
NSString *
_NS_non_retained_id_describe (void *table, id <NSObject> o)
{
/* Once again, I need a nice way to determine whether O responds to
* `describe'. Help. */
return [o description];
}
/** For (retainable) objects **/
unsigned int
_NS_id_hash (void *table, id <NSObject> o)
{
/* See above. */
return [o hash];
}
@ -174,6 +167,7 @@ _NS_id_describe (void *table, id <NSObject> o)
/** For (non-owned) `void *' **/
unsigned int
_NS_non_owned_void_p_hash (void *table, void *p)
{
@ -205,6 +199,7 @@ _NS_non_owned_void_p_describe (void *table, void *p)
}
/** For pointers to structures and `int *' **/
unsigned int
_NS_int_p_hash (void *table, int *p)
{
@ -232,5 +227,6 @@ _NS_int_p_release (void *table, int *p)
NSString *
_NS_int_p_describe (void *table, int *p)
{
return [NSString stringWithFormat:@"%d (%0x)", *p, p];
/* Is this useful? */
return [NSString stringWithFormat:@"%d (%#x)", *p, p];
}

View file

@ -1,327 +1,426 @@
/* NSGeometry.c - geometry functions
Copyright (C) 1993,1994 Free Software Foundation, Inc.
* Copyright (C) 1993, 1994, 1995 Free Software Foundation, Inc.
*
* Written by: Adam Fedor <fedor@boulder.colorado.edu>
* Date: Mar 1995
*
* This file is part of the GNU Objective C Class Library.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the Free
* Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
Written by: Adam Fedor <fedor@boulder.colorado.edu>
Date: Mar 1995
This file is part of the GNU Objective C Class Library.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public
License along with this library; if not, write to the Free
Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
/**** Included Headers *******************************************************/
#include <math.h>
#include <objects/stdobjects.h>
#include <Foundation/NSString.h>
#include <Foundation/NSGeometry.h>
/* Create Basic Structures */
/**** Type, Constant, and Macro Definitions **********************************/
/**** Function Implementations ***********************************************/
/** Create Basic Structures... **/
NSPoint
NSMakePoint(float x, float y)
{
NSPoint point;
point.x = x;
point.y = y;
return point;
NSPoint point;
point.x = x;
point.y = y;
return point;
}
NSSize
NSMakeSize(float w, float h)
{
NSSize size;
size.width = w;
size.height = h;
return size;
NSSize size;
size.width = w;
size.height = h;
return size;
}
NSRect
NSMakeRect(float x, float y, float w, float h)
{
NSRect rect;
rect.origin.x = x;
rect.origin.y = y;
rect.size.width = w;
rect.size.height = h;
return rect;
NSRect rect;
rect.origin.x = x;
rect.origin.y = y;
rect.size.width = w;
rect.size.height = h;
return rect;
}
/* Get ractangle coordinates */
/** Get a Rectangle's Coordinates... **/
float
NSMaxX(NSRect aRect)
{
return aRect.origin.x + aRect.size.width;
return aRect.origin.x + aRect.size.width;
}
float
NSMaxY(NSRect aRect)
{
return aRect.origin.y + aRect.size.height;
return aRect.origin.y + aRect.size.height;
}
float
NSMidX(NSRect aRect)
{
return aRect.origin.x + aRect.size.width / 2.0;
return aRect.origin.x + (aRect.size.width / 2.0);
}
float
NSMidY(NSRect aRect)
{
return aRect.origin.y + aRect.size.height / 2.0;
return aRect.origin.y + (aRect.size.height / 2.0);
}
float
NSMinX(NSRect aRect)
{
return aRect.origin.x;
return aRect.origin.x;
}
float
NSMinY(NSRect aRect)
{
return aRect.origin.y;
return aRect.origin.y;
}
float
NSWidth(NSRect aRect)
{
return aRect.size.width;
return aRect.size.width;
}
float
NSHeight(NSRect aRect)
{
return aRect.size.height;
return aRect.size.height;
}
/* Modify a copy of a rectangle */
/** Modify a Copy of a Rectangle... **/
NSRect
NSOffsetRect(NSRect aRect, float dx, float dy)
{
NSRect rect = aRect;
rect.origin.x += dx;
rect.origin.y += dy;
return rect;
NSRect rect = aRect;
rect.origin.x += dx;
rect.origin.y += dy;
return rect;
}
NSRect
NSInsetRect(NSRect aRect, float dX, float dY)
{
NSRect rect;
rect = NSOffsetRect(aRect, dX, dY);
rect.size.width -= (2*dX);
rect.size.height -= (2*dY);
return rect;
NSRect rect;
rect = NSOffsetRect(aRect, dX, dY);
rect.size.width -= (2 * dX);
rect.size.height -= (2 * dY);
return rect;
}
void
NSDivideRect(NSRect aRect,
NSRect *slice,
NSRect *remainder,
float amount,
NSRectEdge edge)
{
static NSRect sRect, rRect;
if (!slice)
slice = &sRect;
if (!remainder)
remainder = &rRect;
if (NSIsEmptyRect(aRect))
{
*slice = NSMakeRect(0,0,0,0);
*remainder = NSMakeRect(0,0,0,0);
return;
}
switch (edge)
{
case NSMinXEdge:
if (amount > aRect.size.width)
{
*slice = aRect;
*remainder = NSMakeRect(NSMaxX(aRect),
aRect.origin.y,
0,
aRect.size.height);
}
else
{
*slice = NSMakeRect(aRect.origin.x,
aRect.origin.y,
amount,
aRect.size.height);
*remainder = NSMakeRect(NSMaxX(*slice),
aRect.origin.y,
NSMaxX(aRect) - NSMaxX(*slice),
aRect.size.height);
}
break;
case NSMinYEdge:
if (amount > aRect.size.height)
{
*slice = aRect;
*remainder = NSMakeRect(aRect.origin.x,
NSMaxY(aRect),
aRect.size.width, 0);
}
else
{
*slice = NSMakeRect(aRect.origin.x,
aRect.origin.y,
aRect.size.width,
amount);
*remainder = NSMakeRect(aRect.origin.x,
NSMaxY(*slice),
aRect.size.width,
NSMaxY(aRect) - NSMaxY(*slice));
}
break;
case (NSMaxXEdge):
if (amount > aRect.size.width)
{
*slice = aRect;
*remainder = NSMakeRect(aRect.origin.x,
aRect.origin.y,
0,
aRect.size.height);
}
else
{
*slice = NSMakeRect(NSMaxX(aRect) - amount,
aRect.origin.y,
amount,
aRect.size.height);
*remainder = NSMakeRect(aRect.origin.x,
aRect.origin.y,
NSMinX(*slice) - aRect.origin.x,
aRect.size.height);
}
break;
case NSMaxYEdge:
if (amount > aRect.size.height)
{
*slice = aRect;
*remainder = NSMakeRect(aRect.origin.x,
aRect.origin.y,
aRect.size.width,
0);
}
else
{
*slice = NSMakeRect(aRect.origin.x,
NSMaxY(aRect) - amount,
aRect.size.width,
amount);
*remainder = NSMakeRect(aRect.origin.x,
aRect.origin.y,
aRect.size.width,
NSMinY(*slice) - aRect.origin.y);
}
break;
default:
break;
}
return;
}
NSRect
NSIntegralRect(NSRect aRect)
{
NSRect rect;
if (NSIsEmptyRect(aRect)) {
return NSMakeRect(0, 0, 0, 0);
}
NSRect rect;
if (NSIsEmptyRect(aRect))
return NSMakeRect(0, 0, 0, 0);
rect.origin.x = floor(aRect.origin.x);
rect.origin.y = floor(aRect.origin.y);
rect.size.width = ceil(aRect.size.width);
rect.size.height = ceil(aRect.size.height);
return rect;
rect.origin.x = floor(aRect.origin.x);
rect.origin.y = floor(aRect.origin.y);
rect.size.width = ceil(aRect.size.width);
rect.size.height = ceil(aRect.size.height);
return rect;
}
void
NSDivideRect(NSRect aRect, NSRect *slice, NSRect *remainder,
float amount, NSRectEdge edge)
{
static NSRect sRect, rRect;
if (!slice)
slice = &sRect;
if (!remainder)
remainder = &rRect;
if (NSIsEmptyRect(aRect)) {
*slice = NSMakeRect(0,0,0,0);
*remainder = NSMakeRect(0,0,0,0);
return;
}
switch (edge) {
case (NSMinXEdge):
if (amount > aRect.size.width) {
*slice = aRect;
*remainder = NSMakeRect(NSMaxX(aRect), aRect.origin.y,
0, aRect.size.height);
} else {
*slice = NSMakeRect(aRect.origin.x, aRect.origin.y, amount,
aRect.size.height);
*remainder = NSMakeRect(NSMaxX(*slice), aRect.origin.y,
NSMaxX(aRect)-NSMaxX(*slice), aRect.size.height);
}
break;
case (NSMinYEdge):
if (amount > aRect.size.height) {
*slice = aRect;
*remainder = NSMakeRect(aRect.origin.x, NSMaxY(aRect),
aRect.size.width, 0);
} else {
*slice = NSMakeRect(aRect.origin.x, aRect.origin.y,
aRect.size.width, amount);
*remainder = NSMakeRect(aRect.origin.x, NSMaxY(*slice),
aRect.size.width, NSMaxY(aRect)-NSMaxY(*slice));
}
break;
case (NSMaxXEdge):
if (amount > aRect.size.width) {
*slice = aRect;
*remainder = NSMakeRect(aRect.origin.x, aRect.origin.y,
0, aRect.size.height);
} else {
*slice = NSMakeRect(NSMaxX(aRect)-amount, aRect.origin.y,
amount, aRect.size.height);
*remainder = NSMakeRect(aRect.origin.x, aRect.origin.y,
NSMinX(*slice)-aRect.origin.x, aRect.size.height);
}
break;
case (NSMaxYEdge):
if (amount > aRect.size.height) {
*slice = aRect;
*remainder = NSMakeRect(aRect.origin.x, aRect.origin.y,
aRect.size.width, 0);
} else {
*slice = NSMakeRect(aRect.origin.x, NSMaxY(aRect)-amount,
aRect.size.width, amount);
*remainder = NSMakeRect(aRect.origin.x, aRect.origin.y,
aRect.size.width, NSMinY(*slice)-aRect.origin.y);
}
break;
default:
break;
}
}
/* Compute a third rectangle from two rectangles */
/** Compute a Third Rectangle from Two Rectangles... **/
NSRect
NSUnionRect(NSRect aRect, NSRect bRect)
{
NSRect rect;
if (NSIsEmptyRect(aRect) && NSIsEmptyRect(bRect))
return NSMakeRect(0,0,0,0);
else if (NSIsEmptyRect(aRect))
return bRect;
else if (NSIsEmptyRect(bRect))
return aRect;
NSRect rect;
rect = NSMakeRect(MIN(NSMinX(aRect), NSMinX(bRect)),
MIN(NSMinY(aRect), NSMinY(bRect)), 0, 0);
rect = NSMakeRect(NSMinX(rect), NSMinY(rect),
MAX(NSMaxX(aRect), NSMaxX(bRect)) - NSMinX(rect),
MAX(NSMaxY(aRect), NSMaxY(bRect)) - NSMinY(rect));
return rect;
if (NSIsEmptyRect(aRect) && NSIsEmptyRect(bRect))
return NSMakeRect(0,0,0,0);
else if (NSIsEmptyRect(aRect))
return bRect;
else if (NSIsEmptyRect(bRect))
return aRect;
rect = NSMakeRect(MIN(NSMinX(aRect), NSMinX(bRect)),
MIN(NSMinY(aRect), NSMinY(bRect)), 0, 0);
rect = NSMakeRect(NSMinX(rect),
NSMinY(rect),
MAX(NSMaxX(aRect), NSMaxX(bRect)) - NSMinX(rect),
MAX(NSMaxY(aRect), NSMaxY(bRect)) - NSMinY(rect));
return rect;
}
/* Note that intersecting at a line or a point doesn't count */
/* FIXME: This function isn't listed in the OpenStep Specification. */
BOOL
NSIntersectsRect(NSRect aRect, NSRect bRect)
{
return (NSMaxX(aRect) <= NSMinX(bRect) || \
NSMaxX(bRect) <= NSMinX(aRect) || \
NSMaxY(aRect) <= NSMinY(bRect) || \
NSMaxY(bRect) <= NSMinY(aRect)) ? NO : YES;
/* Note that intersecting at a line or a point doesn't count */
return (NSMaxX(aRect) <= NSMinX(bRect)
|| NSMaxX(bRect) <= NSMinX(aRect)
|| NSMaxY(aRect) <= NSMinY(bRect)
|| NSMaxY(bRect) <= NSMinY(aRect)) ? NO : YES;
}
NSRect
NSIntersectionRect (NSRect aRect, NSRect bRect)
{
NSRect rect;
if (!NSIntersectsRect(aRect, bRect)) {
return NSMakeRect(0, 0, 0, 0);
}
if (NSMinX(aRect) <= NSMinX(bRect)) {
rect.size.width = MIN(NSMaxX(aRect), NSMaxX(bRect)) - NSMinX(bRect);
rect.origin.x = NSMinX(bRect);
} else {
rect.size.width = MIN(NSMaxX(aRect), NSMaxX(bRect)) - NSMinX(aRect);
rect.origin.x = NSMinX(aRect);
}
if (NSMinY(aRect) <= NSMinY(bRect)) {
rect.size.height = MIN(NSMaxY(aRect), NSMaxY(bRect)) - NSMinY(bRect);
rect.origin.y = NSMinY(bRect);
} else {
rect.size.height = MIN(NSMaxY(aRect), NSMaxY(bRect)) - NSMinY(aRect);
rect.origin.y = NSMinY(aRect);
}
return rect;
NSRect rect;
if (!NSIntersectsRect(aRect, bRect))
{
return NSMakeRect(0, 0, 0, 0);
}
if (NSMinX(aRect) <= NSMinX(bRect))
{
rect.size.width = MIN(NSMaxX(aRect), NSMaxX(bRect)) - NSMinX(bRect);
rect.origin.x = NSMinX(bRect);
}
else
{
rect.size.width = MIN(NSMaxX(aRect), NSMaxX(bRect)) - NSMinX(aRect);
rect.origin.x = NSMinX(aRect);
}
if (NSMinY(aRect) <= NSMinY(bRect))
{
rect.size.height = MIN(NSMaxY(aRect), NSMaxY(bRect)) - NSMinY(bRect);
rect.origin.y = NSMinY(bRect);
}
else
{
rect.size.height = MIN(NSMaxY(aRect), NSMaxY(bRect)) - NSMinY(aRect);
rect.origin.y = NSMinY(aRect);
}
return rect;
}
/** Test geometric relationships... **/
/* Test geometrical relationships */
BOOL
NSEqualRects(NSRect aRect, NSRect bRect)
{
return ((NSMinX(aRect) == NSMinX(bRect))
&& (NSMinY(aRect) == NSMinY(bRect))
&& (NSWidth(aRect) == NSWidth(bRect))
&& (NSHeight(aRect) == NSHeight(bRect)));
/* FIXME: Isn't it more efficient to do this by hand, rather than with
* all of these function calls? Maybe this doesn't matter, though. */
return ((NSMinX(aRect) == NSMinX(bRect))
&& (NSMinY(aRect) == NSMinY(bRect))
&& (NSWidth(aRect) == NSWidth(bRect))
&& (NSHeight(aRect) == NSHeight(bRect))) ? YES : NO;
}
BOOL
NSEqualSizes(NSSize aSize, NSSize bSize)
{
return ((aSize.width == bSize.width)
&& (aSize.height == bSize.height));
return ((aSize.width == bSize.width)
&& (aSize.height == bSize.height)) ? YES : NO;
}
BOOL
NSEqualPoints(NSPoint aPoint, NSPoint bPoint)
{
return ((aPoint.x == bPoint.x)
&& (aPoint.y == bPoint.y));
return ((aPoint.x == bPoint.x)
&& (aPoint.y == bPoint.y)) ? YES : NO;
}
BOOL
NSIsEmptyRect(NSRect aRect)
{
return (!((NSWidth(aRect) > 0) && (NSHeight(aRect) > 0)));
return ((NSWidth(aRect) > 0) && (NSHeight(aRect) > 0)) ? NO : YES;
}
BOOL
NSMouseInRect(NSPoint aPoint, NSRect aRect, BOOL flipped)
{
if (flipped)
return ((aPoint.x >= NSMinX(aRect))
&& (aPoint.y >= NSMinY(aRect))
&& (aPoint.x < NSMaxX(aRect))
&& (aPoint.y < NSMaxY(aRect)));
else
return ((aPoint.x >= NSMinX(aRect))
&& (aPoint.y > NSMinY(aRect))
&& (aPoint.x < NSMaxX(aRect))
&& (aPoint.y <= NSMaxY(aRect)));
if (flipped)
return ((aPoint.x >= NSMinX(aRect))
&& (aPoint.y >= NSMinY(aRect))
&& (aPoint.x < NSMaxX(aRect))
&& (aPoint.y < NSMaxY(aRect))) ? YES : NO;
else
return ((aPoint.x >= NSMinX(aRect))
&& (aPoint.y > NSMinY(aRect))
&& (aPoint.x < NSMaxX(aRect))
&& (aPoint.y <= NSMaxY(aRect))) ? YES : NO;
}
BOOL
NSPointInRect(NSPoint aPoint, NSRect aRect)
{
return NSMouseInRect(aPoint, aRect, YES);
return NSMouseInRect(aPoint, aRect, YES);
}
BOOL
NSContainsRect(NSRect aRect, NSRect bRect)
{
return ((NSMinX(aRect) < NSMinX(bRect)) &&
(NSMinY(aRect) < NSMinY(bRect)) &&
(NSMaxX(aRect) > NSMaxX(bRect)) &&
(NSMaxY(aRect) > NSMaxY(bRect)));
return ((NSMinX(aRect) < NSMinX(bRect))
&& (NSMinY(aRect) < NSMinY(bRect))
&& (NSMaxX(aRect) > NSMaxX(bRect))
&& (NSMaxY(aRect) > NSMaxY(bRect))) ? YES : NO;
}
/** Get a String Representation... **/
NSString *
NSStringFromPoint(NSPoint aPoint)
{
return [NSString stringWithFormat:@"{x=%f; y=%f}", aPoint.x, aPoint.y];
}
NSString *
NSStringFromRect(NSRect aRect)
{
return [NSString stringWithFormat:@"{x=%f; y=%f; width=%f; height=%f}",
aRect.origin.x, aRect.origin.y,
aRect.size.width, aRect.size.height];
}
NSString *
NSStringFromSize(NSSize aSize)
{
return [NSString stringWithFormat:@"{width=%f; height=%f}",
aSize.width, aSize.height];
}

View file

@ -3,8 +3,8 @@
*
* Author: Albin L. Jones <Albin.L.Jones@Dartmouth.EDU>
* Created: Mon Dec 12 23:54:09 EST 1994
* Updated: Mon Feb 12 22:55:15 EST 1996
* Serial: 96.02.12.01
* Updated: Mon Mar 11 01:48:31 EST 1996
* Serial: 96.03.11.06
*
* This file is part of the GNU Objective C Class Library.
*
@ -20,19 +20,17 @@
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the Free
* Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*
*/
* Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
/**** Included Headers *******************************************************/
#include <Foundation/NSZone.h>
#include <Foundation/NSString.h>
#include <Foundation/NSArray.h>
#include <Foundation/NSException.h>
#include <Foundation/NSHashTable.h>
#include <NSCallBacks.h>
#include <Foundation/atoz.h>
#include <objects/hash.h>
#include "NSCallBacks.h"
/**** Type, Constant, and Macro Definitions **********************************/
@ -43,7 +41,7 @@ typedef void (*NSHT_retain_func_t)(NSHashTable *, const void *);
typedef void (*NSHT_release_func_t)(NSHashTable *, void *);
typedef NSString *(*NSHT_describe_func_t)(NSHashTable *, const void *);
/** Standard NSHashTable callbacks **/
/** Standard NSHashTable callbacks... **/
const NSHashTableCallBacks NSIntHashCallBacks =
{
@ -99,116 +97,117 @@ const NSHashTableCallBacks NSPointerToStructHashCallBacks =
(NSHT_describe_func_t) _NS_int_p_describe
};
/** Macros **/
#define NSHT_ZONE(T) \
((NSZone *)((objects_hash_allocs((objects_hash_t *)(T))).user_data))
/** Macros... **/
#define NSHT_CALLBACKS(T) \
(*((NSHashTableCallBacks *)(objects_hash_extra((objects_hash_t *)(T)))))
#define NSHT_DESCRIBE(T, P) \
NSHT_CALLBACKS((T)).describe((T), (P))
(NSHT_CALLBACKS((T))).describe((T), (P))
/** Dummy callbacks **/
/** Dummy callbacks... **/
size_t
_NSHT_hash (const void *element, const void *table)
_NSHT_hash(const void *element, NSHashTable *table)
{
return (NSHT_CALLBACKS(table)).hash ((NSHashTable *)table, element);
return (NSHT_CALLBACKS(table)).hash((NSHashTable *)table, element);
}
int
_NSHT_compare (const void *element1, const void *element2, const void *table)
_NSHT_compare(const void *element1, const void *element2, NSHashTable *table)
{
return !((NSHT_CALLBACKS(table)).isEqual ((NSHashTable *)table,
element1,
element2));
return !((NSHT_CALLBACKS(table)).isEqual(table, element1, element2));
}
int
_NSHT_is_equal (const void *element1, const void *element2, const void *table)
_NSHT_is_equal(const void *element1, const void *element2, NSHashTable *table)
{
return (NSHT_CALLBACKS(table)).isEqual ((NSHashTable *) table,
element1,
element2);
return (NSHT_CALLBACKS(table)).isEqual(table, element1, element2);
}
void *
_NSHT_retain (const void *element, const void *table)
const void *
_NSHT_retain(const void *element, NSHashTable *table)
{
(NSHT_CALLBACKS(table)).retain ((NSHashTable *)table, element);
return (void*) element;
/* OpenStep (unlike we) does not allow for the possibility of
* substitution upon retaining. */
(NSHT_CALLBACKS(table)).retain(table, element);
return element;
}
void
_NSHT_release (void *element, const void *table)
_NSHT_release(void *element, NSHashTable *table)
{
(NSHT_CALLBACKS(table)).release ((NSHashTable*)table, (void*)element);
(NSHT_CALLBACKS(table)).release(table, element);
return;
}
/* These are wrappers for getting at the real callbacks. */
const objects_callbacks_t _NSHT_callbacks =
NSString *
_NSHT_describe(const void *element, const void *table)
{
_NSHT_hash,
_NSHT_compare,
_NSHT_is_equal,
_NSHT_retain,
_NSHT_release,
0,
0
return ((NSHT_CALLBACKS(table)).describe((NSHashTable *)table, element));
}
/* These are wrappers for getting at the real callbacks. */
objects_callbacks_t _NSHT_callbacks =
{
(objects_hash_func_t) _NSHT_hash,
(objects_compare_func_t) _NSHT_compare,
(objects_is_equal_func_t) _NSHT_is_equal,
(objects_retain_func_t) _NSHT_retain,
(objects_release_func_t) _NSHT_release,
(objects_describe_func_t) _NSHT_describe,
0 /* Note that OpenStep decrees that '0' is the (only) forbidden value. */
};
/** Extra, extra **/
/* Make a copy of a hash table's callbacks. */
void *
_NSHT_extra_retain (const void *extra, const void *table)
const void *
_NSHT_extra_retain (const NSHashTableCallBacks *callBacks, NSHashTable *table)
{
/* Pick out the callbacks in EXTRA. */
NSHashTableCallBacks *callBacks = (NSHashTableCallBacks *)(extra);
/* Find our zone. */
NSZone *zone = NSHT_ZONE(table);
/* A pointer to some new callbacks. */
NSHashTableCallBacks *newCallBacks;
/* Set aside space for our new callbacks in the right zone. */
newCallBacks = (NSHashTableCallBacks *)
NSZoneMalloc(zone,
sizeof(NSHashTableCallBacks));
newCallBacks = (NSHashTableCallBacks *)NSZoneMalloc(objects_hash_zone(table),
sizeof(NSHashTableCallBacks));
/* FIXME: Check for an invalid pointer? */
/* Copy CALLBACKS into NEWCALLBACKS. */
*newCallBacks = *callBacks;
/* Return our new EXTRA. */
return (void*) extra;
/* Return our new callbacks. */
return (const void *) newCallBacks;
}
void
_NSHT_extra_release (void *extra, const void *table)
_NSHT_extra_release(NSHashTableCallBacks *callBacks, NSHashTable *table)
{
NSZone *zone = NSHT_ZONE(table);
if (extra != NULL)
NSZoneFree(zone, (void*)extra);
if (callBacks != 0)
NSZoneFree(objects_hash_zone(table), callBacks);
return;
}
NSString *
_NSHT_extra_describe(NSHashTableCallBacks *callBacks, NSHashTable *table)
{
/* FIXME: Code this. */
return nil;
}
/* The idea here is that these callbacks ensure that the
* NSHashTableCallbacks which are associated with a given NSHashTable
* remain so associated throughout the life of the table and its copies. */
objects_callbacks_t _NSHT_extra_callbacks =
{
(objects_hash_func_t) objects_void_p_hash,
(objects_compare_func_t) objects_void_p_compare,
(objects_is_equal_func_t) objects_void_p_is_equal,
_NSHT_extra_retain,
_NSHT_extra_release,
0,
(objects_hash_func_t) objects_non_owned_void_p_hash,
(objects_compare_func_t) objects_non_owned_void_p_compare,
(objects_is_equal_func_t) objects_non_owned_void_p_is_equal,
(objects_retain_func_t) _NSHT_extra_retain,
(objects_release_func_t) _NSHT_extra_release,
(objects_describe_func_t) _NSHT_extra_describe,
0
};
@ -216,71 +215,55 @@ objects_callbacks_t _NSHT_extra_callbacks =
/** Creating NSHashTables **/
NSHashTable *
NSCreateHashTableWithZone (NSHashTableCallBacks callBacks,
unsigned int capacity,
NSZone *zone)
inline NSHashTable *
NSCreateHashTableWithZone(NSHashTableCallBacks callBacks,
unsigned int capacity,
NSZone *zone)
{
NSHashTable *table;
objects_callbacks_t callbacks;
objects_allocs_t allocs;
/* These callbacks just look in the TABLE's extra and uses the
* callbacks there. See above for precise definitions. */
callbacks = _NSHT_callbacks;
allocs = objects_allocs_for_zone(zone);
/* Build the core table. See the above for the definitions of
* the funny callbacks. */
table = objects_hash_with_zone_with_callbacks(zone, _NSHT_callbacks);
/* Then we build the table. */
table = objects_hash_with_allocs_with_callbacks(allocs, callbacks);
if (table != NULL)
/* Check to make sure our allocation has succeeded. */
if (table != 0)
{
const void *extra;
/* Resize TABLE to CAPACITY. */
objects_hash_resize(table, capacity);
/* Set aside space for the NSHashTableExtra. */
extra = &callBacks;
/* Add EXTRA to TABLE. This takes care of everything for us. */
/* Add CALLBACKS to TABLE. This takes care of everything for us. */
objects_hash_set_extra_callbacks(table, _NSHT_extra_callbacks);
objects_hash_set_extra(table, extra);
objects_hash_set_extra(table, &callBacks);
}
/* Wah-hoo! */
/* Yah-hoo, kid! */
return table;
}
NSHashTable *
NSCreateHashTable (NSHashTableCallBacks callBacks,
unsigned int capacity)
NSCreateHashTable(NSHashTableCallBacks callBacks,
unsigned int capacity)
{
return NSCreateHashTableWithZone(callBacks, capacity, NULL);
return NSCreateHashTableWithZone(callBacks, capacity, 0);
}
/** Copying **/
NSHashTable *
NSCopyHashTableWithZone (NSHashTable *table, NSZone *zone)
NSCopyHashTableWithZone(NSHashTable *table, NSZone *zone)
{
objects_allocs_t allocs;
NSHashTable *new_table;
/* Due to the wonders of modern Libfn technology, everything we care
* about is automagically transferred. */
allocs = objects_allocs_for_zone(zone);
new_table = objects_hash_copy_with_allocs(table, allocs);
return new_table;
/* Due to the wonders of modern structure technology,
* everything we care about is automagically and safely destroyed. */
return objects_hash_copy_with_zone(table, zone);
}
/** Destroying **/
void
NSFreeHashTable (NSHashTable *table)
NSFreeHashTable(NSHashTable *table)
{
/* Due to the wonders of modern Libobjects structure technology,
/* Due to the wonders of modern technology,
* everything we care about is automagically and safely destroyed. */
objects_hash_dealloc(table);
return;
@ -289,7 +272,7 @@ NSFreeHashTable (NSHashTable *table)
/** Resetting **/
void
NSResetHashTable (NSHashTable *table)
NSResetHashTable(NSHashTable *table)
{
objects_hash_empty(table);
return;
@ -298,7 +281,7 @@ NSResetHashTable (NSHashTable *table)
/** Comparing **/
BOOL
NSCompareHashTables (NSHashTable *table1, NSHashTable *table2)
NSCompareHashTables(NSHashTable *table1, NSHashTable *table2)
{
return (objects_hash_is_equal_to_hash(table1, table2) ? YES : NO);
}
@ -306,7 +289,7 @@ NSCompareHashTables (NSHashTable *table1, NSHashTable *table2)
/** Counting **/
unsigned int
NSCountHashTable (NSHashTable *table)
NSCountHashTable(NSHashTable *table)
{
return (unsigned int) objects_hash_count(table);
}
@ -314,10 +297,10 @@ NSCountHashTable (NSHashTable *table)
/** Retrieving **/
void *
NSHashGet (NSHashTable *table, const void *pointer)
NSHashGet(NSHashTable *table, const void *pointer)
{
/* Just make the call. You know the number. */
return (void*) objects_hash_element (table, pointer);
return (void *) objects_hash_element(table, pointer);
}
NSArray *
@ -339,44 +322,44 @@ NSAllHashTableObjects (NSHashTable *table)
while ((element = NSNextHashEnumeratorItem(&enumerator)) != 0)
[array addObject:element];
/* FIXME: Should ARRAY returned be `autorelease'd? */
return [array autorelease];
/* ARRAY is already autoreleased. */
return (NSArray *) array;
}
/** Enumerating **/
NSHashEnumerator
NSEnumerateHashTable (NSHashTable *table)
NSEnumerateHashTable(NSHashTable *table)
{
return objects_hash_enumerator (table);
return objects_hash_enumerator_for_hash(table);
}
void *
NSNextHashEnumeratorItem (NSHashEnumerator *enumerator)
NSNextHashEnumeratorItem(NSHashEnumerator *enumerator)
{
const void *element;
/* Grab the next element. */
objects_hash_enumerator_next_element (enumerator, &element);
objects_hash_enumerator_next_element(enumerator, &element);
/* Return ELEMENT. */
return (void*) element;
return (void *) element;
}
/** Adding **/
void
NSHashInsert (NSHashTable *table, const void *pointer)
NSHashInsert(NSHashTable *table, const void *pointer)
{
/* Place POINTER in TABLE. */
objects_hash_add_element (table, pointer);
objects_hash_add_element(table, pointer);
/* OpenStep doesn't care for any return value, so... */
return;
}
void
NSHashInsertKnownAbsent (NSHashTable *table, const void *element)
NSHashInsertKnownAbsent(NSHashTable *table, const void *element)
{
if (objects_hash_contains_element(table, element))
{
@ -384,7 +367,7 @@ NSHashInsertKnownAbsent (NSHashTable *table, const void *element)
* information. Not difficult to do, just something for a later
* date. */
[NSException raise:NSInvalidArgumentException
format:@"Attempted reinsertion of \"%@\" into a hash table.",
format:@"NSHashTable: illegal reinsertion of: %@",
NSHT_DESCRIBE(table, element)];
}
else
@ -392,11 +375,12 @@ NSHashInsertKnownAbsent (NSHashTable *table, const void *element)
objects_hash_add_element_known_absent(table, element);
}
/* OpenStep doesn't care for any return value, so... */
return;
}
void *
NSHashInsertIfAbsent (NSHashTable *table, const void *element)
NSHashInsertIfAbsent(NSHashTable *table, const void *element)
{
const void *old_element;
@ -404,13 +388,13 @@ NSHashInsertIfAbsent (NSHashTable *table, const void *element)
old_element = objects_hash_add_element_if_absent(table, element);
/* Return the version of ELEMENT in TABLE now. */
return (void*) old_element;
return (void *) old_element;
}
/** Removing **/
void
NSHashRemove (NSHashTable *table, const void *element)
NSHashRemove(NSHashTable *table, const void *element)
{
/* Remove ELEMENT from TABLE. */
objects_hash_remove_element(table, element);
@ -421,11 +405,8 @@ NSHashRemove (NSHashTable *table, const void *element)
/** Describing **/
/* FIXME: Make this nicer. I don't know what is desired here, though.
* If somebody has a clear idea of what this string should look like,
* please tell me, and I'll make it happen. */
NSString *
NSStringFromHashTable (NSHashTable *table)
NSStringFromHashTable(NSHashTable *table)
{
NSMutableString *string;
NSHashEnumerator enumerator;
@ -440,9 +421,8 @@ NSStringFromHashTable (NSHashTable *table)
/* Iterate over the elements of TABLE, appending the description of
* each to the mutable string STRING. */
while ((pointer = NSNextHashEnumeratorItem(&enumerator)) != 0)
[string appendFormat:@"%@;", NSHT_DESCRIBE(table, pointer)];
[string appendFormat:@"%@;\n", NSHT_DESCRIBE(table, pointer)];
/* Note that this string'll need to be `retain'ed. */
/* FIXME: Should I `autorelease' STRING? I think so. */
return (NSString *)[string autorelease];
/* STRING is already autoreleased. */
return (NSString *) string;
}

View file

@ -3,8 +3,8 @@
*
* Author: Albin L. Jones <Albin.L.Jones@Dartmouth.EDU>
* Created: Mon Dec 12 23:59:57 EST 1994
* Updated: Sat Feb 10 16:00:25 EST 1996
* Serial: 96.02.10.01
* Updated: Sun Mar 17 18:37:12 EST 1996
* Serial: 96.03.17.31
*
* This file is part of the GNU Objective C Class Library.
*
@ -20,9 +20,7 @@
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the Free
* Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*
*/
* Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
/**** Included Headers *******************************************************/
@ -31,9 +29,8 @@
#include <Foundation/NSArray.h>
#include <Foundation/NSException.h>
#include <Foundation/NSMapTable.h>
#include <NSCallBacks.h>
#include <Foundation/atoz.h>
#include <objects/map.h>
#include "NSCallBacks.h"
/**** Type, Constant, and Macro Definitions **********************************/
@ -145,10 +142,7 @@ const NSMapTableValueCallBacks NSOwnedPointerMapValueCallBacks =
(NSMT_describe_func_t) _NS_owned_void_p_describe
};
/** Macros **/
#define NSMT_ZONE(T) \
((NSZone *)((objects_map_allocs((objects_map_t *)(T))).user_data))
/** Macros... **/
#define NSMT_EXTRA(T) \
((_NSMT_extra_t *)(objects_map_extra((objects_map_t *)(T))))
@ -165,7 +159,7 @@ const NSMapTableValueCallBacks NSOwnedPointerMapValueCallBacks =
#define NSMT_DESCRIBE_VALUE(T, P) \
NSMT_VALUE_CALLBACKS((T)).describe((T), (P))
/** Dummy callbacks **/
/** Dummy callbacks... **/
size_t
_NSMT_key_hash (const void *element, const void *table)
@ -200,101 +194,119 @@ _NSMT_key_retain (const void *element, const void *table)
}
void
_NSMT_key_release (void *element, const void *table)
_NSMT_key_release (void *element, void *table)
{
NSMT_KEY_CALLBACKS(table).release ((NSMapTable*)table, element);
return;
}
NSString *
_NSMT_key_describe(const void *element, void *table)
{
return nil;
}
void *
_NSMT_value_retain (const void *element, const void *table)
{
NSMT_VALUE_CALLBACKS(table).retain ((NSMapTable *)table, element);
return (void*) element;
NSMT_VALUE_CALLBACKS(table).retain((NSMapTable *)table, element);
return (void *) element;
}
void
_NSMT_value_release (void *element, const void *table)
{
NSMT_VALUE_CALLBACKS(table).release ((NSMapTable*)table, element);
NSMT_VALUE_CALLBACKS(table).release((NSMapTable *)table, element);
return;
}
NSString *
_NSMT_value_describe(const void *element, const void *table)
{
/* FIXME: Code this. */
return nil;
}
/* These are wrappers for getting at the real callbacks. */
objects_callbacks_t _NSMT_key_callbacks =
{
_NSMT_key_hash,
_NSMT_key_compare,
_NSMT_key_is_equal,
_NSMT_key_retain,
_NSMT_key_release,
0,
0
(objects_hash_func_t) _NSMT_key_hash,
(objects_compare_func_t) _NSMT_key_compare,
(objects_is_equal_func_t) _NSMT_key_is_equal,
(objects_retain_func_t) _NSMT_key_retain,
(objects_release_func_t) _NSMT_key_release,
(objects_describe_func_t) _NSMT_key_describe,
0 /* This gets changed...See just below. */
};
objects_callbacks_t
_NSMT_callbacks_for_key_callbacks (NSMapTableKeyCallBacks keyCallBacks)
static inline objects_callbacks_t
_NSMT_callbacks_for_key_callbacks(NSMapTableKeyCallBacks keyCallBacks)
{
objects_callbacks_t cb = _NSMT_key_callbacks;
objects_callbacks_t cbs = _NSMT_key_callbacks;
cb.not_an_item_marker = keyCallBacks.notAKeyMarker;
cbs.not_an_item_marker = keyCallBacks.notAKeyMarker;
return cb;
return cbs;
}
objects_callbacks_t _NSMT_value_callbacks =
{
(objects_hash_func_t) objects_void_p_hash,
(objects_compare_func_t) objects_void_p_compare,
(objects_is_equal_func_t) objects_void_p_is_equal,
_NSMT_value_retain,
_NSMT_value_release,
0,
0
(objects_hash_func_t) objects_non_owned_void_p_hash,
(objects_compare_func_t) objects_non_owned_void_p_compare,
(objects_is_equal_func_t) objects_non_owned_void_p_is_equal,
(objects_retain_func_t) _NSMT_value_retain,
(objects_release_func_t) _NSMT_value_release,
(objects_describe_func_t) _NSMT_value_describe,
0 /* Not needed, really, for OpenStep...And so, ignored here. */
};
/** Extra, extra **/
/* Make a copy of a hash table's callbacks. */
void *
_NSMT_extra_retain(const void *extra, const void *table)
const void *
_NSMT_extra_retain(_NSMT_extra_t *extra, NSMapTable *table)
{
/* A pointer to some space for new callbacks. */
_NSMT_extra_t *new_extra;
/* Set aside space for our new callbacks in the right zone. */
new_extra = (_NSMT_extra_t *)NSZoneMalloc(NSMT_ZONE(table),
sizeof(_NSMT_extra_t));
new_extra = (_NSMT_extra_t *)NSZoneMalloc(objects_map_zone(table),
sizeof(_NSMT_extra_t));
/* Copy the old callbacks into NEW_EXTRA. */
*new_extra = *((_NSMT_extra_t *)(extra));
*new_extra = *extra;
/* Return our new EXTRA. */
return new_extra;
}
void
_NSMT_extra_release(void *extra, const void *table)
_NSMT_extra_release(void *extra, NSMapTable *table)
{
NSZone *zone = NSMT_ZONE(table);
if (extra != 0)
NSZoneFree(zone, extra);
NSZoneFree(objects_map_zone(table), extra);
return;
}
/* The idea here is that these callbacks ensure that the
* NSMapTableCallbacks which are associated with a given NSMapTable
NSString *
_NSMT_extra_describe(const void *extra, NSMapTable *table)
{
/* FIXME: Code this. */
return nil;
}
/* The basic idea here is that these callbacks ensure that the
* NSMapTable...Callbacks which are associated with a given NSMapTable
* remain so throughout the life of the table and its copies. */
objects_callbacks_t _NSMT_extra_callbacks =
{
(objects_hash_func_t) objects_void_p_hash,
(objects_compare_func_t) objects_void_p_compare,
(objects_is_equal_func_t) objects_void_p_is_equal,
_NSMT_extra_retain,
_NSMT_extra_release,
0,
(objects_hash_func_t) objects_non_owned_void_p_hash,
(objects_compare_func_t) objects_non_owned_void_p_compare,
(objects_is_equal_func_t) objects_non_owned_void_p_is_equal,
(objects_retain_func_t) _NSMT_extra_retain,
(objects_release_func_t)_NSMT_extra_release,
(objects_describe_func_t)_NSMT_extra_describe,
0
};
@ -302,7 +314,7 @@ objects_callbacks_t _NSMT_extra_callbacks =
/** Creating an NSMapTable **/
NSMapTable *
inline NSMapTable *
NSCreateMapTableWithZone(NSMapTableKeyCallBacks keyCallBacks,
NSMapTableValueCallBacks valueCallBacks,
unsigned capacity,
@ -310,18 +322,14 @@ NSCreateMapTableWithZone(NSMapTableKeyCallBacks keyCallBacks,
{
NSMapTable *table;
objects_callbacks_t key_callbacks, value_callbacks;
objects_allocs_t allocs;
/* Transform the callbacks we were given. */
key_callbacks = _NSMT_callbacks_for_key_callbacks(keyCallBacks);
value_callbacks = _NSMT_value_callbacks;
/* Get some useful allocs. */
allocs = objects_allocs_for_zone(zone);
/* Create a map table. */
table = objects_map_with_allocs_with_callbacks(allocs, key_callbacks,
value_callbacks);
table = objects_map_with_zone_with_callbacks(zone, key_callbacks,
value_callbacks);
/* Adjust the capacity of TABLE. */
objects_map_resize(table, capacity);
@ -358,11 +366,9 @@ NSCreateMapTable(NSMapTableKeyCallBacks keyCallBacks,
NSMapTable *
NSCopyMapTableWithZone(NSMapTable *table, NSZone *zone)
{
objects_allocs_t allocs;
NSMapTable *new_table;
allocs = objects_allocs_for_zone(zone);
new_table = objects_map_copy_with_allocs(table, allocs);
new_table = objects_map_copy_with_zone(table, zone);
return new_table;
}
@ -383,7 +389,7 @@ NSResetMapTable(NSMapTable *table)
return;
}
/** Comparing two NSMapTables **/
/** Comparing two NSMapTables... **/
BOOL
NSCompareMapTables(NSMapTable *table1, NSMapTable *table2)
@ -408,7 +414,8 @@ NSMapMember(NSMapTable *table, const void *key,
int i;
/* Check for K in TABLE. */
i = objects_map_key_and_value_at_key (table, key, originalKey, value);
i = objects_map_key_and_value_at_key(table, (const void **)originalKey,
(const void **)value, key);
/* Indicate our state of success. */
return i ? YES : NO;
@ -417,13 +424,13 @@ NSMapMember(NSMapTable *table, const void *key,
void *
NSMapGet(NSMapTable *table, const void *key)
{
return (void*) objects_map_value_at_key (table, key);
return (void *) objects_map_value_at_key(table, key);
}
NSMapEnumerator
NSEnumerateMapTable(NSMapTable *table)
{
return objects_map_enumerator(table);
return objects_map_enumerator_for_map(table);
}
BOOL
@ -433,9 +440,9 @@ NSNextMapEnumeratorPair(NSMapEnumerator *enumerator,
int i;
/* Get the next pair. */
i = objects_map_enumerator_next_key_and_value (enumerator,
(const void**)key,
(const void**)value);
i = objects_map_enumerator_next_key_and_value(enumerator,
(const void **)key,
(const void **)value);
/* Indicate our success or failure. */
return i ? YES : NO;
@ -446,17 +453,17 @@ NSAllMapTableKeys(NSMapTable *table)
{
NSMutableArray *keyArray;
NSMapEnumerator enumerator;
id key;
id key = nil;
/* Create our mutable key array. */
keyArray = [NSMutableArray arrayWithCapacity: NSCountMapTable (table)];
keyArray = [NSMutableArray arrayWithCapacity:NSCountMapTable(table)];
/* Get an enumerator for TABLE. */
enumerator = NSEnumerateMapTable (table);
enumerator = NSEnumerateMapTable(table);
/* Step through TABLE... */
while (NSNextMapEnumeratorPair (&enumerator, (void**)&key, 0))
[keyArray addObject: key];
while (NSNextMapEnumeratorPair(&enumerator, (void **)(&key), 0))
[keyArray addObject:key];
return keyArray;
}
@ -466,7 +473,7 @@ NSAllMapTableValues(NSMapTable *table)
{
NSMapEnumerator enumerator;
NSMutableArray *valueArray;
id value;
id value = nil;
/* Create our mutable value array. */
valueArray = [NSMutableArray arrayWithCapacity:NSCountMapTable(table)];
@ -475,19 +482,19 @@ NSAllMapTableValues(NSMapTable *table)
enumerator = NSEnumerateMapTable(table);
/* Step through TABLE... */
while (NSNextMapEnumeratorPair (&enumerator, 0, (void**)&value))
while (NSNextMapEnumeratorPair(&enumerator, 0, (void **)(&value)))
[valueArray addObject:value];
return valueArray;
}
/** Adding items to an NSMapTable **/
/** Adding items to an NSMapTable... **/
void
NSMapInsert(NSMapTable *table, const void *key, const void *value)
{
/* Put KEY -> VALUE into TABLE. */
objects_map_at_key_put_value (table, key, value);
objects_map_at_key_put_value(table, key, value);
return;
}
@ -495,15 +502,13 @@ NSMapInsert(NSMapTable *table, const void *key, const void *value)
void *
NSMapInsertIfAbsent(NSMapTable *table, const void *key, const void *value)
{
void *old_key;
if (objects_map_contains_key (table, key))
return (void*) objects_map_key (table, key);
return (void *) objects_map_key_at_key(table, key);
else
{
/* Put KEY -> VALUE into TABLE. */
objects_map_at_key_put_value_known_absent (table, key, value);
return NULL;
return 0;
}
}
@ -513,10 +518,13 @@ NSMapInsertKnownAbsent(NSMapTable *table, const void *key, const void *value)
/* Is the key already in the table? */
if (objects_map_contains_key(table, key))
{
/* Ooh. Bad. The docs say to raise an exception! */
/* FIXME: I should make this much more informative. */
/* FIXME: I should make this give the user/programmer more
* information. Not difficult to do, just something for a later
* date. */
[NSException raise:NSInvalidArgumentException
format:@"That key's already in the table."];
format:@"NSMapTable: illegal reinsertion of: %@ -> %@",
NSMT_DESCRIBE_KEY(table, key),
NSMT_DESCRIBE_VALUE(table, value)];
}
else
{
@ -565,6 +573,5 @@ NSStringFromMapTable(NSMapTable *table)
(valueCallBacks.describe)(table, value)];
/* Note that this string'll need to be `retain'ed. */
/* FIXME: Should I be `autorelease'ing it? */
return [string autorelease];
return string;
}

View file

@ -1,46 +0,0 @@
/* A hookable abort function.
* Copyright (C) 1996 Free Software Foundation, Inc.
*
* Author: Albin L. Jones <Albin.L.Jones@Dartmouth.EDU>
* Created: Sat Feb 10 12:31:57 EST 1996
* Updated: Sat Feb 10 12:31:57 EST 1996
* Serial: 96.02.10.01
*
* This file is part of the GNU Objective C Class Library.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the Free
* Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*
*/
/**** Included Headers *******************************************************/
#include <stdio.h>
#include <objects/abort.h>
/**** Type, Constant, and Macro Definitions **********************************/
static void (*__objects_abort) (void) = NULL;
/**** Function Implementations ***********************************************/
void
objects_abort (void)
{
if (__objects_abort != NULL)
(__objects_abort) ();
else
abort ();
return;
}

View file

@ -1,81 +0,0 @@
/* Modular memory management through structures.
* Copyright (C) 1994, 1995, 1996 Free Software Foundation, Inc.
*
* Author: Albin L. Jones <Albin.L.Jones@Dartmouth.EDU>
* Created: Thu Oct 13 23:45:49 EDT 1994
* Updated: Sat Feb 10 15:19:32 EST 1996
* Serial: 96.02.10.03
*
* This file is part of the GNU Objective C Class Library.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the Free
* Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*
*/
/**** Included Headers *******************************************************/
#include <objects/allocs.h>
/**** Type, Constant, and Macro Definitions **********************************/
static objects_allocs_t __objects_allocs_standard =
{
(objects_malloc_func_t) malloc,
(objects_calloc_func_t) calloc,
(objects_realloc_func_t) realloc,
(objects_free_func_t) free,
(const void *) 0
};
/**** Function Implementations ***********************************************/
objects_allocs_t
objects_allocs_standard (void)
{
return __objects_allocs_standard;
}
void *
objects_malloc (objects_allocs_t allocs, size_t s)
{
return (*(allocs.malloc)) (s, allocs.user_data);
}
void *
objects_calloc (objects_allocs_t allocs, size_t n, size_t s)
{
return (*(allocs.calloc)) (n, s, allocs.user_data);
}
void *
objects_realloc (objects_allocs_t allocs, const void *p, size_t s)
{
return (*(allocs.realloc)) ((void*)p, s, allocs.user_data);
}
void
objects_free (objects_allocs_t allocs, const void *p)
{
(*(allocs.free)) ((void*)p, allocs.user_data);
return;
}
size_t
objects_next_power_of_two (size_t beat)
{
size_t start = 1;
while ((start <= beat) && (start <<= 1));
return start;
}

View file

@ -1,906 +0,0 @@
/* A (pretty good) implementation of a sparse array.
* Copyright (C) 1994, 1995, 1996 Free Software Foundation, Inc.
*
* Author: Albin L. Jones <Albin.L.Jones@Dartmouth.EDU>
* Created: Thu Mar 2 02:28:50 EST 1994
* Updated: Sat Feb 10 16:16:12 EST 1996
* Serial: 96.02.10.02
*
* This file is part of the GNU Objective C Class Library.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the Free
* Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*
*/
/**** Included Headers *******************************************************/
#include <objects/allocs.h>
#include <objects/callbacks.h>
#include <objects/abort.h>
#include <objects/array.h>
#include <objects/hash.h>
/**** Function Implementations ***********************************************/
/** Background functions **/
size_t
_objects_array_fold_index (size_t index, size_t slot_count)
{
return (slot_count ? (index % slot_count) : 0);
}
size_t
_objects_array_internal_index (objects_array_t * array, size_t index)
{
return _objects_array_fold_index (index, array->slot_count);
}
objects_array_slot_t *
_objects_array_slot_for_index (objects_array_t * array, size_t index)
{
return (array->slots + _objects_array_internal_index (array, index));
}
objects_array_bucket_t *
_objects_array_bucket_for_index (objects_array_t * array, size_t index)
{
objects_array_slot_t *slot;
objects_array_bucket_t *bucket;
/* First, we translate the index into a bucket index to find our
* candidate for the bucket. */
slot = _objects_array_slot_for_index (array, index);
bucket = *slot;
/* But we need to check to see whether this is really the bucket we
* wanted. */
if (bucket != NULL && bucket->index == index)
/* Bucket `index' exists, and we've got it, so... */
return bucket;
else
/* Either no bucket or some other bucket is where bucket `index'
* would be, if it existed. So... */
return NULL;
}
objects_array_bucket_t *
_objects_array_new_bucket (objects_array_t * array, size_t index, const void *element)
{
objects_array_bucket_t *bucket;
bucket = (objects_array_bucket_t *) objects_malloc (objects_array_allocs (array),
sizeof (objects_array_bucket_t));
if (bucket != NULL)
{
objects_retain (objects_array_element_callbacks (array), element, array);
bucket->index = index;
bucket->element = element;
}
return bucket;
}
void
_objects_array_free_bucket (objects_array_t * array, objects_array_bucket_t * bucket)
{
if (bucket != NULL)
{
objects_release (objects_array_element_callbacks (array),
(void*)bucket->element,
array);
objects_free (objects_array_allocs (array), bucket);
}
return;
}
objects_array_slot_t *
_objects_array_new_slots (objects_array_t * array, size_t slot_count)
{
return (objects_array_slot_t *) objects_calloc (objects_array_allocs (array),
slot_count,
sizeof (objects_array_slot_t));
}
void
_objects_array_free_slots (objects_array_t * array, objects_array_slot_t * slots)
{
if (slots != NULL)
objects_free (objects_array_allocs (array), slots);
return;
}
void
_objects_array_empty_slot (objects_array_t * array, objects_array_slot_t * slot)
{
if (*slot != NULL)
{
/* Get rid of the bucket. */
_objects_array_free_bucket (array, *slot);
/* Mark the slot as empty. */
*slot = NULL;
/* Keep the element count accurate */
--(array->element_count);
}
/* And return. */
return;
}
void
_objects_array_insert_bucket (objects_array_t * array, objects_array_bucket_t * bucket)
{
objects_array_slot_t *slot;
slot = _objects_array_slot_for_index (array, bucket->index);
/* We're adding a bucket, so the current set of sorted slots is now
* invalidated. */
if (array->sorted_slots != NULL)
{
_objects_array_free_slots (array, array->sorted_slots);
array->sorted_slots = NULL;
}
if ((*slot) == NULL)
{
/* There's nothing there, so we can put `bucket' there. */
*slot = bucket;
/* Increment the array's bucket counter. */
++(array->element_count);
return;
}
if ((*slot)->index == bucket->index)
{
/* There's a bucket there, and it has the same index as `bucket'.
* So we get rid of the old one, and put the new one in its
* place. */
_objects_array_free_bucket (array, *slot);
*slot = bucket;
return;
}
else
{
/* Now we get to fiddle around with things to make the world a
* better place... */
size_t new_slot_count;
objects_array_slot_t *new_slots; /* This guy holds the buckets while we
* muck about with them. */
size_t d; /* Just a counter */
/* FIXME: I *really* wish I had a way of generating
* statistically better initial values for this variable. So
* I'll run a few tests and see... And is there a better
* algorithm, e.g., a better collection of sizes in the sense
* that the likelyhood of fitting everything in earlier is
* high? Well, enough mumbling. */
/* At any rate, we're guaranteed to need at least this many. */
new_slot_count = array->element_count + 1;
do
{
/* First we make a new pile of slots for the buckets. */
new_slots = _objects_array_new_slots (array, new_slot_count);
if (new_slots == NULL)
objects_abort ();
/* Then we put the new bucket in the pile. */
new_slots[_objects_array_fold_index (bucket->index,
new_slot_count)] = bucket;
/* Now loop and try to place the others. Upon collision
* with a previously inserted bucket, try again with more
* `new_slots'. */
for (d = 0; d < array->slot_count; ++d)
{
if (array->slots[d] != NULL)
{
size_t i;
i = _objects_array_fold_index (array->slots[d]->index,
new_slot_count);
if (new_slots[i] == NULL)
{
new_slots[i] = array->slots[d];
}
else
{
/* A collision. Clean up and try again. */
/* Free the current set of new buckets. */
_objects_array_free_slots (array, new_slots);
/* Bump up the number of new buckets. */
++new_slot_count;
/* Break out of the `for' loop. */
break;
}
}
}
}
while (d < array->slot_count);
if (array->slots != NULL)
_objects_array_free_slots (array, array->slots);
array->slots = new_slots;
array->slot_count = new_slot_count;
++(array->element_count);
return;
}
}
int
_objects_array_compare_slots (const objects_array_slot_t * slot1,
const objects_array_slot_t * slot2)
{
if (slot1 == slot2)
return 0;
if (*slot1 == NULL)
return 1;
if (*slot2 == NULL)
return -1;
if ((*slot1)->index < (*slot2)->index)
return -1;
else if ((*slot1)->index > (*slot2)->index)
return 1;
else
return 0;
}
typedef int (*qsort_compare_func_t) (const void *, const void *);
void
_objects_array_make_sorted_slots (objects_array_t * array)
{
objects_array_slot_t *new_slots;
/* If there're already some sorted slots, then they're valid, and
* we're done. */
if (array->sorted_slots != NULL)
return;
/* Make some new slots. */
new_slots = _objects_array_new_slots (array, array->slot_count);
/* Copy the pointers to buckets into the new slots. */
memcpy (new_slots, array->slots, (array->slot_count
* sizeof (objects_array_slot_t)));
/* Sort the new slots. */
qsort (new_slots, array->slot_count, sizeof (objects_array_slot_t),
(qsort_compare_func_t) _objects_array_compare_slots);
/* Put the newly sorted slots in the `sorted_slots' element of the
* array structure. */
array->sorted_slots = new_slots;
return;
}
objects_array_bucket_t *
_objects_array_enumerator_next_bucket (objects_array_enumerator_t * enumerator)
{
if (enumerator->is_sorted)
{
if (enumerator->is_ascending)
{
if (enumerator->array->sorted_slots == NULL)
return NULL;
if (enumerator->index < enumerator->array->element_count)
{
objects_array_bucket_t *bucket;
bucket = enumerator->array->sorted_slots[enumerator->index];
++(enumerator->index);
return bucket;
}
else
return NULL;
}
else
{
if (enumerator->array->sorted_slots == NULL)
return NULL;
if (enumerator->index > 0)
{
objects_array_bucket_t *bucket;
--(enumerator->index);
bucket = enumerator->array->sorted_slots[enumerator->index];
return bucket;
}
else
return NULL;
}
}
else
{
objects_array_bucket_t *bucket;
if (enumerator->array->slots == NULL)
return NULL;
for (bucket = NULL;
(enumerator->index < enumerator->array->slot_count
&& bucket == NULL);
++(enumerator->index))
{
bucket = enumerator->array->slots[enumerator->index];
}
return bucket;
}
}
/** Statistics **/
size_t
objects_array_count (objects_array_t * array)
{
return array->element_count;
}
size_t
objects_array_capacity (objects_array_t * array)
{
return array->slot_count;
}
int
objects_array_check (objects_array_t * array)
{
return 0;
}
int
objects_array_is_empty (objects_array_t * array)
{
return objects_array_count (array) != 0;
}
/** Emptying **/
void
objects_array_empty (objects_array_t * array)
{
size_t c;
/* Just empty each slot out, one by one. */
for (c = 0; c < array->slot_count; ++c)
_objects_array_empty_slot (array, array->slots + c);
return;
}
/** Creating **/
objects_array_t *
objects_array_alloc_with_allocs (objects_allocs_t allocs)
{
objects_array_t *array;
/* Get a new array. */
array = _objects_array_alloc_with_allocs (allocs);
return array;
}
objects_array_t *
objects_array_alloc (void)
{
return objects_array_alloc_with_allocs (objects_allocs_standard ());
}
objects_array_t *
objects_array_with_allocs (objects_allocs_t allocs)
{
return objects_array_init (objects_array_alloc_with_allocs (allocs));
}
objects_array_t *
objects_array_with_allocs_with_callbacks (objects_allocs_t allocs,
objects_callbacks_t callbacks)
{
return objects_array_init_with_callbacks (objects_array_alloc_with_allocs (allocs),
callbacks);
}
objects_array_t *
objects_array_with_callbacks (objects_callbacks_t callbacks)
{
return objects_array_init_with_callbacks (objects_array_alloc (), callbacks);
}
objects_array_t *
objects_array_of_char_p (void)
{
return objects_array_with_callbacks (objects_callbacks_for_char_p);
}
objects_array_t *
objects_array_of_void_p (void)
{
return objects_array_with_callbacks (objects_callbacks_for_void_p);
}
objects_array_t *
objects_array_of_owned_void_p (void)
{
return objects_array_with_callbacks (objects_callbacks_for_owned_void_p);
}
objects_array_t *
objects_array_of_int (void)
{
return objects_array_with_callbacks (objects_callbacks_for_int);
}
objects_array_t *
objects_array_of_id (void)
{
return objects_array_with_callbacks (objects_callbacks_for_id);
}
/** Initializing **/
objects_array_t *
objects_array_init_with_callbacks (objects_array_t * array, objects_callbacks_t callbacks)
{
if (array != NULL)
{
/* The default capacity is 15. */
size_t capacity = 15;
/* Record the element callbacks. */
array->callbacks = objects_callbacks_standardize (callbacks);
/* Initialize ARRAY's information. */
array->element_count = 0;
array->slot_count = capacity + 1;
/* Make some new slots. */
array->slots = _objects_array_new_slots (array, capacity + 1);
/* Get the sorted slots ready for later use. */
array->sorted_slots = NULL;
}
return array;
}
objects_array_t *
objects_array_init (objects_array_t * array)
{
return objects_array_init_with_callbacks (array,
objects_callbacks_standard());
}
objects_array_t *
objects_array_init_from_array (objects_array_t * array, objects_array_t * old_array)
{
objects_array_enumerator_t enumerator;
size_t index;
const void *element;
/* Initialize ARRAY in the usual way. */
objects_array_init_with_callbacks (array,
objects_array_element_callbacks (old_array));
/* Get an enumerator for OLD_ARRAY. */
enumerator = objects_array_enumerator (old_array);
/* Step through OLD_ARRAY's elements, putting them at the proper
* index in ARRAY. */
while (objects_array_enumerator_next_index_and_element (&enumerator,
&index, &element))
{
objects_array_at_index_put_element (array, index, element);
}
return array;
}
/** Destroying **/
void
objects_array_dealloc (objects_array_t * array)
{
if (array != NULL)
{
/* Empty out ARRAY. */
objects_array_empty (array);
/* Free up its slots. */
_objects_array_free_slots (array, array->slots);
/* FIXME: What about ARRAY's sorted slots? */
/* Free up ARRAY itself. */
_objects_array_dealloc (array);
}
return;
}
/** Searching **/
const void *
objects_array_element_at_index (objects_array_t * array, size_t index)
{
objects_array_bucket_t *bucket = _objects_array_bucket_for_index (array, index);
if (bucket != NULL)
return bucket->element;
else
/* If `bucket' is NULL, then the requested index is unused. */
/* There's no bucket, so... */
return objects_array_not_an_element_marker (array);
}
size_t
objects_array_index_of_element (objects_array_t * array, const void *element)
{
size_t i;
for (i = 0; i < array->slot_count; ++i)
{
objects_array_bucket_t *bucket = array->slots[i];
if (bucket != NULL)
if (objects_is_equal (objects_array_element_callbacks (array),
bucket->element,
element,
array))
return bucket->index;
}
return i;
}
int
objects_array_contains_element (objects_array_t * array, const void *element)
{
/* Note that this search is quite inefficient. */
return objects_array_index_of_element (array, element) < (array->slot_count);
}
const void **
objects_array_all_elements (objects_array_t * array)
{
objects_array_enumerator_t enumerator;
const void **elements;
size_t count, i;
count = objects_array_count (array);
/* Set aside space to hold the elements. */
elements = (const void **) objects_calloc (objects_array_allocs (array),
count + 1,
sizeof (const void *));
enumerator = objects_array_enumerator (array);
for (i = 0; i < count; ++i)
objects_array_enumerator_next_element (&enumerator, elements + i);
elements[i] = objects_array_not_an_element_marker (array);
/* We're done, so heave it back. */
return elements;
}
const void **
objects_array_all_elements_ascending (objects_array_t * array)
{
objects_array_enumerator_t enumerator;
const void **elements;
size_t count, i;
count = objects_array_count (array);
/* Set aside space to hold the elements. */
elements = (const void **) objects_calloc (objects_array_allocs (array),
count + 1,
sizeof (const void *));
enumerator = objects_array_ascending_enumerator (array);
for (i = 0; i < count; ++i)
objects_array_enumerator_next_element (&enumerator, elements + i);
elements[i] = objects_array_not_an_element_marker (array);
/* We're done, so heave it back. */
return elements;
}
const void **
objects_array_all_elements_descending (objects_array_t * array)
{
objects_array_enumerator_t enumerator;
const void **elements;
size_t count, i;
count = objects_array_count (array);
/* Set aside space to hold the elements. */
elements = (const void **) objects_calloc (objects_array_allocs (array),
count + 1,
sizeof (const void *));
enumerator = objects_array_descending_enumerator (array);
for (i = 0; i < count; ++i)
objects_array_enumerator_next_element (&enumerator, elements + i);
elements[i] = objects_array_not_an_element_marker (array);
/* We're done, so heave it back. */
return elements;
}
/** Removing **/
void
objects_array_remove_element_at_index (objects_array_t * array, size_t index)
{
objects_array_bucket_t *bucket;
/* Get the bucket that might be there. */
bucket = _objects_array_bucket_for_index (array, index);
/* If there's a bucket at the index, then we empty its slot out. */
if (bucket != NULL)
_objects_array_empty_slot (array, _objects_array_slot_for_index (array, index));
/* Finally, we return. */
return;
}
void
objects_array_remove_element_known_present (objects_array_t * array,
const void *element)
{
objects_array_remove_element_at_index (array,
objects_array_index_of_element (array,
element));
return;
}
void
objects_array_remove_element (objects_array_t * array, const void *element)
{
if (objects_array_contains_element (array, element))
objects_array_remove_element_known_present (array, element);
return;
}
/** Adding **/
const void *
objects_array_at_index_put_element (objects_array_t * array,
size_t index,
const void *element)
{
objects_array_bucket_t *bucket;
/* Clean out anything that's already there. */
objects_array_remove_element_at_index (array, index);
/* Make a bucket for our information. */
bucket = _objects_array_new_bucket (array, index, element);
/* Put our bucket in the array. */
_objects_array_insert_bucket (array, bucket);
return element;
}
/** Enumerating **/
objects_array_enumerator_t
objects_array_ascending_enumerator (objects_array_t * array)
{
objects_array_enumerator_t enumerator;
enumerator.array = array;
enumerator.is_sorted = 1;
enumerator.is_ascending = 1;
enumerator.index = 0;
_objects_array_make_sorted_slots (array);
return enumerator;
}
objects_array_enumerator_t
objects_array_descending_enumerator (objects_array_t * array)
{
objects_array_enumerator_t enumerator;
enumerator.array = array;
enumerator.is_sorted = 1;
enumerator.is_ascending = 0;
/* The `+ 1' is so that we have `0' as a known ending condition.
* See `_objects_array_enumerator_next_bucket()'. */
enumerator.index = array->element_count + 1;
_objects_array_make_sorted_slots (array);
return enumerator;
}
objects_array_enumerator_t
objects_array_enumerator (objects_array_t * array)
{
objects_array_enumerator_t enumerator;
enumerator.array = array;
enumerator.is_sorted = 0;
enumerator.is_ascending = 0;
enumerator.index = 0;
return enumerator;
}
int
objects_array_enumerator_next_index_and_element (objects_array_enumerator_t * enumerator,
size_t * index,
const void **element)
{
objects_array_bucket_t *bucket;
bucket = _objects_array_enumerator_next_bucket (enumerator);
if (bucket != NULL)
{
if (element != NULL)
*element = bucket->element;
if (index != NULL)
*index = bucket->index;
return 1;
}
else
{
if (element != NULL)
*element = objects_array_not_an_element_marker (enumerator->array);
if (index != NULL)
*index = 0;
return 0;
}
}
int
objects_array_enumerator_next_element (objects_array_enumerator_t * enumerator,
const void **element)
{
return objects_array_enumerator_next_index_and_element (enumerator,
NULL,
element);
}
int
objects_array_enumerator_next_index (objects_array_enumerator_t * enumerator,
size_t * index)
{
return objects_array_enumerator_next_index_and_element (enumerator,
index,
NULL);
}
/** Comparing **/
int
objects_array_is_equal_to_array (objects_array_t * array1, objects_array_t * array2)
{
size_t a, b;
const void *m, *n;
objects_array_enumerator_t e, f;
a = objects_array_count (array1);
b = objects_array_count (array2);
if (a < b)
return (b - a);
if (a > b)
return (a - b);
/* Get ascending enumerators for each of the two arrays. */
e = objects_array_ascending_enumerator (array1);
e = objects_array_ascending_enumerator (array1);
while (objects_array_enumerator_next_index_and_element (&e, &a, &m)
&& objects_array_enumerator_next_index_and_element (&f, &b, &n))
{
int c, d;
if (a < b)
return (b - a);
if (a > b)
return (a - b);
c = objects_compare (objects_array_element_callbacks (array1), m, n, array1);
if (c != 0)
return c;
d = objects_compare (objects_array_element_callbacks (array2), n, m, array2);
if (d != 0)
return d;
}
return 0;
}
/** Mapping **/
objects_array_t *
objects_array_map_elements (objects_array_t * array,
const void *(*fcn) (const void *, const void *),
const void *user_data)
{
/* FIXME: Code this. */
return array;
}
/** Miscellaneous **/
objects_hash_t *
objects_hash_init_from_array (objects_hash_t * hash, objects_array_t * array)
{
objects_array_enumerator_t enumerator;
const void *element;
/* NOTE: If ARRAY contains multiple elements of the same equivalence
* class, it is indeterminate which will end up in HASH. This
* shouldn't matter, though. */
enumerator = objects_array_enumerator (array);
/* Just walk through ARRAY's elements and add them to HASH. */
while (objects_array_enumerator_next_element (&enumerator, &element))
objects_hash_add_element (hash, element);
return hash;
}
// objects_chash_t *
// objects_chash_init_from_array (objects_chash_t * chash, objects_array_t * array)
// {
// objects_array_enumerator_t enumerator;
// const void *element;
//
// /* NOTE: If ARRAY contains multiple elements of the same equivalence
// * class, it is indeterminate which will end up in CHASH. This
// * shouldn't matter, though. */
// enumerator = objects_array_enumerator (array);
//
// /* Just walk through ARRAY's elements and add them to CHASH. */
// while (objects_array_enumerator_next_element (&enumerator, &element))
// objects_chash_add_element (chash, element);
//
// return chash;
// }

View file

@ -1,76 +0,0 @@
/* Handling the interface between allocs and zones.
* Copyright (C) 1994, 1995, 1996 Free Software Foundation, Inc.
*
* Author: Albin L. Jones <Albin.L.Jones@Dartmouth.EDU>
* Created: Sat Oct 15 10:34:02 EDT 1994
* Updated: Sat Feb 10 15:20:41 EST 1996
* Serial: 96.02.10.02
*
* This file is part of the GNU Objective C Class Library.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the Free
* Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*
*/
/**** Included Headers *******************************************************/
#include <Foundation/NSObject.h>
#include <Foundation/NSString.h>
#include <Foundation/NSZone.h>
#include <objects/allocs.h>
/**** Function Implementations ***********************************************/
/** Handling Libobjects Allocs **/
void *
_objects_zone_malloc(size_t s, const void *z)
{
return NSZoneMalloc((NSZone *)z, s);
}
void *
_objects_zone_calloc(size_t n, size_t s, const void *z)
{
return NSZoneCalloc((NSZone *)z, n, s);
}
void *
_objects_zone_realloc(void *p, size_t s, const void *z)
{
return NSZoneRealloc ((NSZone*)z, p, s);
}
void
_objects_zone_free(void *p, const void *z)
{
NSZoneFree((NSZone *)z, p);
return;
}
objects_allocs_t
objects_allocs_for_zone(NSZone *zone)
{
objects_allocs_t allocs =
{
_objects_zone_malloc,
_objects_zone_calloc,
_objects_zone_realloc,
_objects_zone_free,
zone
};
return allocs;
}

View file

@ -1,129 +0,0 @@
/* Callbacks for strings of `char'.
* Copyright (C) 1996 Free Software Foundation, Inc.
*
* Author: Albin L. Jones <Albin.L.Jones@Dartmouth.EDU>
* Created: Sat Feb 10 22:04:38 EST 1996
* Updated: Sun Feb 11 01:40:09 EST 1996
* Serial: 96.02.11.05
*
* This file is part of the GNU Objective C Class Library.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the Free
* Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*
*/
/**** Included Headers *******************************************************/
#include <stdlib.h>
#include <objects/callbacks.h>
/**** Type, Constant, and Macro Definitions **********************************/
objects_callbacks_t objects_callbacks_for_char_p =
{
(objects_hash_func_t) objects_char_p_hash,
(objects_compare_func_t) objects_char_p_compare,
(objects_is_equal_func_t) objects_char_p_is_equal,
(objects_retain_func_t) objects_char_p_retain,
(objects_release_func_t) objects_char_p_release,
(objects_describe_func_t) objects_char_p_describe,
0
};
/**** Function Implementations ***********************************************/
size_t
objects_char_p_hash (const void *cptr)
{
register char *s = (char *) cptr;
register size_t h = 0;
register size_t c = 0;
while (*s != '\0')
h ^= *(s++) << (c++);
return h;
}
int
objects_char_p_compare (const void *cptr, const void *dptr)
{
register char *s = (char *) cptr;
register char *t = (char *) dptr;
if (s == t)
{
return 0;
}
else
{
register char c;
register char d;
while ((c = *(s++)) == (d = *(s++)))
if (c == '\0')
return 0;
return (c - d);
}
}
/* Determines whether or not CPTR is the same (`NUL'-terminated)
* character string as DPTR. Returns true if CPTR and DPTR are the same,
* and false otherwise. Note that we are performing no
* internationalization here. CPTR and DPTR are taken to be C strings
* in the default (seven or) eight bit character encoding. */
int
objects_char_p_is_equal (register const void *cptr, register const void *dptr)
{
register char *s = (char *) cptr;
register char *t = (char *) dptr;
if (s == t)
{
return 1;
}
else
{
register char c;
register char d;
while ((c = *(s++)) == (d = *(t++)))
if (c == '\0')
return 1;
return 0;
}
}
const void *
objects_char_p_retain (const void *cptr)
{
return cptr;
}
void
objects_char_p_release (const void *cptr)
{
return;
}
const void *
objects_char_p_describe (const void *cptr)
{
/* FIXME: Code this. But first, figure out what it should do, OK? */
return 0;
}

View file

@ -1,97 +0,0 @@
/* Callbacks for the Objective-C object type.
* Copyright (C) 1996 Free Software Foundation, Inc.
*
* Author: Albin L. Jones <Albin.L.Jones@Dartmouth.EDU>
* Created: Sat Feb 10 15:55:51 EST 1996
* Updated: Sun Feb 11 01:42:20 EST 1996
* Serial: 96.02.11.05
*
* This file is part of the GNU Objective C Class Library.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the Free
* Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*
*/
/**** Included Headers *******************************************************/
#include <stdlib.h>
#include <objects/callbacks.h>
#include <objects/stdobjects.h>
/**** Type, Constant, and Macro Definitions **********************************/
objects_callbacks_t objects_callbacks_for_id =
{
(objects_hash_func_t) objects_id_hash,
(objects_compare_func_t) objects_id_compare,
(objects_is_equal_func_t) objects_id_is_equal,
(objects_retain_func_t) objects_id_retain,
(objects_release_func_t) objects_id_release,
(objects_describe_func_t) objects_id_describe,
0
};
/**** Function Implementations ***********************************************/
/* FIXME: It sure would be nice if we had a way of checking whether
* or not these objects responded to the messages we're sending them here.
* We need a way that is independent of whether we have GNUStep objects,
* NEXTSTEP objects, or GNU objects. We could certainly just use the
* same trick that the `respondsToSelector:' method uses, but I'd hoped
* that there was already a built-in call to do this sort of thing. */
size_t
objects_id_hash(const void *obj)
{
return (size_t)[(id)obj hash];
}
int
objects_id_compare(const void *obj, const void *jbo)
{
return (int)[(id)obj compare:(id)jbo];
}
int
objects_id_is_equal(const void *obj, const void *jbo)
{
return (int)[(id)obj isEqual:(id)jbo];
}
const void *
objects_id_retain(const void *obj)
{
return [(id)obj retain];
}
void
objects_id_release(const void *obj)
{
[(id)obj release];
return;
}
const void *
objects_id_describe (const void *obj)
{
/* FIXME: Harrumph. Make all of these describe functions live
* in harmony. Please. */
#if 0
return [(id)obj describe];
#else
return 0;
#endif
}

View file

@ -1,84 +0,0 @@
/* Callbacks for `int' (and smaller) things.
* Copyright (C) 1996 Free Software Foundation, Inc.
*
* Author: Albin L. Jones <Albin.L.Jones@Dartmouth.EDU>
* Created: Sat Feb 10 15:55:51 EST 1996
* Updated: Sun Feb 11 01:47:14 EST 1996
* Serial: 96.02.11.03
*
* This file is part of the GNU Objective C Class Library.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the Free
* Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*
*/
/**** Included Headers *******************************************************/
#include <stdlib.h>
#include <objects/callbacks.h>
/**** Type, Constant, and Macro Definitions **********************************/
objects_callbacks_t objects_callbacks_for_int =
{
(objects_hash_func_t) objects_int_hash,
(objects_compare_func_t) objects_int_compare,
(objects_is_equal_func_t) objects_int_is_equal,
(objects_retain_func_t) objects_int_retain,
(objects_release_func_t) objects_int_release,
(objects_describe_func_t) objects_int_describe,
0
};
/**** Function Implementations ***********************************************/
size_t
objects_int_hash (const void *i)
{
return (size_t)((int)i);
}
int
objects_int_compare (const void *i, const void *j)
{
return ((int)i) - ((int)j);
}
int
objects_int_is_equal (const void *i, const void *j)
{
return ((int)i) == ((int)j);
}
const void *
objects_int_retain (const void *i)
{
return i;
}
void
objects_int_release (const void *i)
{
return;
}
const void *
objects_int_describe (const void *i)
{
/* FIXME: Code this. */
return 0;
}

View file

@ -1,87 +0,0 @@
/* Callbacks for pointers to `int' and (maybe) structures whose first
* field is an `int'. Maybe.
* Copyright (C) 1996 Free Software Foundation, Inc.
*
* Author: Albin L. Jones <Albin.L.Jones@Dartmouth.EDU>
* Created: Sat Feb 10 15:55:51 EST 1996
* Updated: Sun Feb 11 01:49:55 EST 1996
* Serial: 96.02.11.04
*
* This file is part of the GNU Objective C Class Library.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the Free
* Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*
*/
/**** Included Headers *******************************************************/
#include <stdlib.h>
#include <objects/callbacks.h>
/**** Type, Constant, and Macro Definitions **********************************/
objects_callbacks_t objects_callbacks_for_int_p =
{
(objects_hash_func_t) objects_int_p_hash,
(objects_compare_func_t) objects_int_p_compare,
(objects_is_equal_func_t) objects_int_p_is_equal,
(objects_retain_func_t) objects_int_p_retain,
(objects_release_func_t) objects_int_p_release,
(objects_describe_func_t) objects_int_p_describe,
0
};
/**** Function Implementations ***********************************************/
size_t
objects_int_p_hash (const void *iptr)
{
return (size_t)(*((int *)iptr));
}
/* FIXME: Are these next two correct? These seem rather useless to me. */
int
objects_int_p_compare (const void *iptr, const void *jptr)
{
return *((int *)iptr) - *((int *)jptr);
}
int
objects_int_p_is_equal (const void *iptr, const void *jptr)
{
return *((int *)iptr) == *((int *)jptr);
}
const void *
objects_int_p_retain (const void *iptr)
{
return iptr;
}
void
objects_int_p_release (const void *iptr)
{
return;
}
const void *
objects_int_p_describe (const void *iptr)
{
/* FIXME: Code this. */
return 0;
}

View file

@ -1,137 +0,0 @@
/* Callbacks for pointers to `void'.
* Copyright (C) 1996 Free Software Foundation, Inc.
*
* Author: Albin L. Jones <Albin.L.Jones@Dartmouth.EDU>
* Created: Sat Feb 10 22:04:38 EST 1996
* Updated: Sun Feb 11 01:09:34 EST 1996
* Serial: 96.02.11.03
*
* This file is part of the GNU Objective C Class Library.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the Free
* Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*
*/
/**** Included Headers *******************************************************/
#include <stdlib.h>
#include <objects/callbacks.h>
/**** Type, Constant, and Macro Definitions **********************************/
objects_callbacks_t objects_callbacks_for_void_p =
{
(objects_hash_func_t) objects_void_p_hash,
(objects_compare_func_t) objects_void_p_compare,
(objects_is_equal_func_t) objects_void_p_is_equal,
(objects_retain_func_t) objects_void_p_retain,
(objects_release_func_t) objects_void_p_release,
0
};
objects_callbacks_t objects_callbacks_for_owned_void_p =
{
(objects_hash_func_t) objects_owned_void_p_hash,
(objects_compare_func_t) objects_owned_void_p_compare,
(objects_is_equal_func_t) objects_owned_void_p_is_equal,
(objects_retain_func_t) objects_owned_void_p_retain,
(objects_release_func_t) objects_owned_void_p_release,
0
};
/**** Function Implementations ***********************************************/
size_t
objects_void_p_hash (const void *cptr)
{
return ((size_t) cptr)/4;
}
int
objects_void_p_compare (const void *cptr, const void *dptr)
{
if (cptr == dptr)
return 0;
else if (cptr < dptr)
return -1;
else /* if (cptr > dptr) */
return 1;
}
int
objects_void_p_is_equal (register const void *cptr, register const void *dptr)
{
return (cptr == dptr);
}
const void *
objects_void_p_retain (const void *cptr)
{
return cptr;
}
void
objects_void_p_release (const void *cptr)
{
return;
}
size_t
objects_owned_void_p_hash (const void *cptr)
{
/* We divide by 4 because many machines align
* memory on word boundaries. */
return ((size_t) cptr)/4;
}
int
objects_owned_void_p_compare (const void *cptr, const void *dptr)
{
if (cptr == dptr)
return 0;
else if (cptr < dptr)
return -1;
else /* if (cptr > dptr) */
return 1;
}
int
objects_owned_void_p_is_equal(register const void *cptr,
register const void *dptr)
{
return (cptr == dptr);
}
const void *
objects_owned_void_p_retain(const void *cptr)
{
return cptr;
}
void
objects_owned_void_p_release (const void *cptr)
{
free ((void*)cptr);
return;
}
const void *
objects_void_p_describe (const void *obj)
{
/* FIXME: Harrumph. Make all of these describe functions live
* in harmony. Please. */
return 0;
}

View file

@ -1,145 +0,0 @@
/* Handling various types in a uniform manner.
* Copyright (C) 1994, 1995, 1996 Free Software Foundation, Inc.
*
* Author: Albin L. Jones <Albin.L.Jones@Dartmouth.EDU>
* Created: Sun Oct 9 13:14:41 EDT 1994
* Updated: Sun Feb 11 01:33:41 EST 1996
* Serial: 96.02.10.07
*
* This file is part of the GNU Objective C Class Library.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the Free
* Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*
*/
/**** Included Headers *******************************************************/
#include <objects/callbacks.h>
/**** Type, Constant, and Macro Definitions **********************************/
/* WARNING: Don't change this unless you know what you're getting into! */
static objects_callbacks_t ___objects_callbacks_standard =
{
(objects_hash_func_t) objects_void_p_hash,
(objects_compare_func_t) objects_void_p_compare,
(objects_is_equal_func_t) objects_void_p_is_equal,
(objects_retain_func_t) objects_void_p_retain,
(objects_release_func_t) objects_void_p_release,
(objects_describe_func_t) objects_void_p_describe,
0
};
/**** Function Implementations ***********************************************/
/** Getting the standard callbacks **/
objects_callbacks_t
objects_callbacks_standard(void)
{
return ___objects_callbacks_standard;
}
/** Standardizing callbacks **/
objects_callbacks_t
objects_callbacks_standardize(objects_callbacks_t callbacks)
{
if (callbacks.hash == 0)
callbacks.hash = objects_callbacks_standard().hash;
if (callbacks.compare == 0 && callbacks.is_equal == 0)
{
callbacks.compare = objects_callbacks_standard().compare;
callbacks.is_equal = objects_callbacks_standard().is_equal;
}
if (callbacks.retain == 0)
callbacks.retain = objects_callbacks_standard().retain;
if (callbacks.release == 0)
callbacks.release = objects_callbacks_standard().release;
return callbacks;
}
/** Using callbacks **/
size_t
objects_hash (objects_callbacks_t callbacks,
const void *thing, const void *user_data)
{
if (callbacks.hash != 0)
return callbacks.hash(thing, user_data);
else
return objects_callbacks_standard().hash(thing, user_data);
}
int
objects_compare (objects_callbacks_t callbacks,
const void *thing1,
const void *thing2,
const void *user_data)
{
if (callbacks.compare != 0)
return callbacks.compare(thing1, thing2, user_data);
else if (callbacks.is_equal != 0)
return !(callbacks.is_equal(thing1, thing2, user_data));
else
return objects_callbacks_standard().compare(thing1, thing2, user_data);
}
int
objects_is_equal (objects_callbacks_t callbacks,
const void *thing1,
const void *thing2,
const void *user_data)
{
if (callbacks.is_equal != 0)
return callbacks.is_equal(thing1, thing2, user_data);
else if (callbacks.compare != 0)
return !(callbacks.compare(thing1, thing2, user_data));
else
return objects_callbacks_standard().is_equal(thing1, thing2, user_data);
}
void *
objects_retain (objects_callbacks_t callbacks,
const void *thing, const void *user_data)
{
if (callbacks.retain != 0)
return callbacks.retain(thing, user_data);
else
return objects_callbacks_standard().retain(thing, user_data);
}
void
objects_release (objects_callbacks_t callbacks,
void *thing, const void *user_data)
{
if (callbacks.release != 0)
callbacks.release (thing, user_data);
else
objects_callbacks_standard().release (thing, user_data);
return;
}
void *
objects_describe(objects_callbacks_t callbacks,
const void *thing, const void *user_data)
{
if (callbacks.release != 0)
return callbacks.describe(thing, user_data);
else
return objects_callbacks_standard().describe(thing, user_data);
}

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff

View file

@ -1,912 +0,0 @@
/* A (pretty good) list implementation.
* Copyright (C) 1995, 1996 Free Software Foundation, Inc.
*
* Author: Albin L. Jones <Albin.L.Jones@Dartmouth.EDU>
* Created: Tue Sep 5 17:23:50 EDT 1995
* Updated: Sat Feb 10 14:50:36 EST 1996
* Serial: 96.02.10.03
*
* This file is part of the GNU Objective C Class Library.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the Free
* Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*
*/
/**** Included Headers *******************************************************/
#include <objects/allocs.h>
#include <objects/callbacks.h>
#include <objects/list.h>
#include <objects/hash.h>
/**** Function Implementations ***********************************************/
/** Background functions **/
inline void
_objects_list_remove_node_from_its_list (objects_list_node_t * node)
{
if (node->list->first_node == node)
node->list->first_node = node->next_in_list;
if (node->list->last_node == node)
node->list->last_node = node->prev_in_list;
if (node->next_in_list != NULL)
node->next_in_list->prev_in_list = node->prev_in_list;
if (node->prev_in_list != NULL)
node->prev_in_list->next_in_list = node->next_in_list;
node->list->node_count -= 1;
node->list->element_count -= 1;
return;
}
objects_list_node_t *
_objects_list_new_node (objects_list_t * list, const void *element)
{
objects_list_node_t *node;
node = objects_malloc (objects_list_allocs (list), sizeof (objects_list_node_t));
if (node != NULL)
{
node->list = list;
node->next_in_list = NULL;
node->prev_in_list = NULL;
objects_retain (objects_list_element_callbacks (list), element, list);
node->element = element;
}
return node;
}
void
_objects_list_free_node (objects_list_t * list, objects_list_node_t * node)
{
objects_release (objects_list_element_callbacks (node->list),
(void*)node->element,
node->list);
objects_free (objects_list_allocs (list), node);
return;
}
inline objects_list_node_t *
_objects_list_nth_node (objects_list_t * list, long int n)
{
objects_list_node_t *node;
if (n < 0)
{
node = list->last_node;
++n;
while (node != NULL && n != 0)
{
node = node->prev_in_list;
++n;
}
}
else
/* (n >= 0) */
{
node = list->first_node;
while (node != NULL && n != 0)
{
node = node->next_in_list;
--n;
}
}
return node;
}
inline objects_list_node_t *
_objects_list_nth_node_for_element (objects_list_t * list,
long int n,
const void *element)
{
objects_list_node_t *node;
if (n < 0)
{
node = list->last_node;
++n;
while (node != NULL && n != 0)
{
if (objects_is_equal (objects_list_element_callbacks (list), element, node->element, list))
++n;
if (n != 0)
node = node->prev_in_list;
}
}
else
{
node = list->first_node;
while (node != NULL && n != 0)
{
if (objects_is_equal (objects_list_element_callbacks (list), element, node->element, list))
--n;
if (n != 0)
node = node->next_in_list;
}
}
return node;
}
inline objects_list_node_t *
_objects_list_enumerator_next_node (objects_list_enumerator_t * enumerator)
{
objects_list_node_t *node;
/* Remember ENUMERATOR's current node. */
node = enumerator->node;
/* If NODE is a real node, then we need to increment ENUMERATOR's
* current node to the next node in ENUMERATOR's list. */
if (node != NULL)
{
if (enumerator->forward)
enumerator->node = enumerator->node->next_in_list;
else /* (!enumerator->forward) */
enumerator->node = enumerator->node->prev_in_list;
}
/* Send back NODE. */
return node;
}
/** Gathering statistics **/
size_t
objects_list_count (objects_list_t * list)
{
return list->element_count;
}
size_t
objects_list_capacity (objects_list_t * list)
{
return list->element_count;
}
int
objects_list_check (objects_list_t * list)
{
return 0;
}
int
objects_list_contains_element (objects_list_t * list, const void *element)
{
objects_list_enumerator_t enumerator;
const void *member;
objects_list_enumerator (list);
while (objects_list_enumerator_next_element (&enumerator, &member))
if (objects_compare (objects_list_element_callbacks (list), element, member, list))
return 1;
return 0;
}
int
objects_list_is_empty (objects_list_t * list)
{
return objects_list_count (list) == 0;
}
/** Enumerating **/
objects_list_enumerator_t
objects_list_enumerator (objects_list_t * list)
{
return objects_list_forward_enumerator (list);
}
objects_list_enumerator_t
objects_list_forward_enumerator (objects_list_t * list)
{
objects_list_enumerator_t enumerator;
/* Update the access time. */
_objects_list_set_access_time (list);
/* Make sure ENUMERATOR knows its list. */
enumerator.list = list;
/* Start ENUMERATOR at LIST's first node. */
enumerator.node = list->first_node;
/* ENUMERATOR walks forward. */
enumerator.forward = 1;
return enumerator;
}
objects_list_enumerator_t
objects_list_reverse_enumerator (objects_list_t * list)
{
objects_list_enumerator_t enumerator;
/* Make sure ENUMERATOR knows its list. */
enumerator.list = list;
/* Start ENUMERATOR at LIST's first node. */
enumerator.node = list->last_node;
/* ENUMERATOR walks backward. */
enumerator.forward = 0;
return enumerator;
}
int
objects_list_enumerator_next_element (objects_list_enumerator_t * enumerator,
const void **element)
{
objects_list_node_t *node;
/* Try and get the next node in the enumeration represented by
* ENUMERATOR. */
node = _objects_list_enumerator_next_node (enumerator);
if (node != NULL)
{
/* If NODE is real, then return the element it contains. */
if (element != NULL)
*element = node->element;
/* Indicate that the enumeration continues. */
return 1;
}
else
{
/* If NODE isn't real, then we return the ``bogus'' indicator. */
if (element != NULL)
*element = objects_list_not_an_element_marker (enumerator->list);
/* Indicate that the enumeration is over. */
return 0;
}
}
/** Searching **/
const void *
objects_list_element (objects_list_t * list, const void *element)
{
objects_list_node_t *node;
node = _objects_list_nth_node_for_element (list, 0, element);
if (node != NULL)
return node->element;
else
return objects_list_not_an_element_marker (list);
}
const void *
objects_list_nth_element (objects_list_t * list, long int n)
{
objects_list_node_t *node;
node = _objects_list_nth_node (list, n);
if (node != NULL)
return node->element;
else
return objects_list_not_an_element_marker (list);
}
const void *
objects_list_first_element (objects_list_t * list)
{
if (list->first_node != NULL)
return list->first_node->element;
else
return objects_list_not_an_element_marker (list);
}
const void *
objects_list_last_element (objects_list_t * list)
{
if (list->last_node != NULL)
return list->last_node->element;
else
return objects_list_not_an_element_marker (list);
}
/** Obtaining elements **/
const void **
objects_list_all_elements (objects_list_t * list)
{
objects_list_enumerator_t enumerator;
const void **array;
size_t i;
array = objects_calloc (objects_list_allocs (list),
objects_list_count (list) + 1,
sizeof (const void *));
for (i = 0; objects_list_enumerator_next_element (&enumerator, array + i); ++i);
return array;
}
/** Adding elements **/
const void *
objects_list_append_element (objects_list_t * list, const void *element)
{
return objects_list_at_index_insert_element (list, -1, element);
}
const void *
objects_list_append_element_if_absent (objects_list_t * list, const void *element)
{
return objects_list_at_index_insert_element_if_absent (list, -1, element);
}
const void *
objects_list_prepend_element (objects_list_t * list, const void *element)
{
return objects_list_at_index_insert_element (list, 0, element);
}
const void *
objects_list_prepend_element_if_absent (objects_list_t * list, const void *element)
{
return objects_list_at_index_insert_element_if_absent (list, 0, element);
}
const void *
objects_list_at_index_insert_element (objects_list_t * list,
long int n,
const void *element)
{
objects_list_node_t *anode, *bnode, *new_node, *node;
node = _objects_list_nth_node (list, n);
new_node = _objects_list_new_node (list, element);
if (new_node == NULL)
objects_abort ();
if (n < 0)
{
if (node == NULL)
{
anode = NULL;
bnode = list->first_node;
}
else
/* (node != NULL) */
{
anode = node;
bnode = node->next_in_list;
}
}
else
/* (n >= 0) */
{
if (node == NULL)
{
anode = list->last_node;
bnode = NULL;
}
else
/* (node != NULL) */
{
anode = node->prev_in_list;
bnode = node;
}
}
new_node->prev_in_list = anode;
new_node->next_in_list = bnode;
if (anode != NULL)
anode->next_in_list = new_node;
if (bnode != NULL)
bnode->prev_in_list = new_node;
if (list->last_node == anode)
list->last_node = new_node;
if (list->first_node == bnode)
list->first_node = new_node;
list->node_count += 1;
list->element_count += 1;
return new_node->element;
}
const void *
objects_list_at_index_insert_element_if_absent (objects_list_t * list,
long int n,
const void *element)
{
if (!objects_list_contains_element (list, element))
return objects_list_at_index_insert_element (list, n, element);
else
return objects_list_element (list, element);
}
/** Removing elements **/
void
objects_list_remove_nth_occurrance_of_element (objects_list_t * list,
long int n,
const void *element)
{
objects_list_node_t *node;
node = _objects_list_nth_node_for_element (list, n, element);
if (node != NULL)
{
_objects_list_remove_node_from_its_list (node);
_objects_list_free_node (list, node);
}
return;
}
void
objects_list_remove_element (objects_list_t * list, const void *element)
{
objects_list_remove_nth_occurrance_of_element (list, 0, element);
return;
}
inline void
objects_list_remove_nth_element (objects_list_t * list, long int n)
{
objects_list_node_t *node;
node = _objects_list_nth_node (list, n);
if (node != NULL)
{
_objects_list_remove_node_from_its_list (node);
_objects_list_free_node (list, node);
}
return;
}
void
objects_list_remove_first_element (objects_list_t * list)
{
objects_list_remove_nth_element (list, 0);
return;
}
void
objects_list_remove_last_element (objects_list_t * list)
{
objects_list_remove_nth_element (list, -1);
return;
}
/** Emptying **/
void
objects_list_empty (objects_list_t * list)
{
objects_list_enumerator_t enumerator;
objects_list_node_t *node;
enumerator = objects_list_enumerator (list);
while ((node = _objects_list_enumerator_next_node (&enumerator)) != NULL)
{
_objects_list_remove_node_from_its_list (node);
_objects_list_free_node (list, node);
}
return;
}
/** Replacing **/
void
objects_list_replace_nth_occurrance_of_element (objects_list_t * list,
long int n,
const void *old_element,
const void *new_element)
{
objects_list_node_t *node;
node = _objects_list_nth_node_for_element (list, n, old_element);
if (node != NULL)
{
objects_retain (objects_list_element_callbacks (list), new_element, list);
objects_release (objects_list_element_callbacks (list),
(void*)node->element,
list);
node->element = new_element;
}
return;
}
void
objects_list_replace_element (objects_list_t * list,
const void *old_element,
const void *new_element)
{
objects_list_replace_nth_occurrance_of_element (list, 0, old_element, new_element);
return;
}
void
objects_list_replace_nth_element (objects_list_t * list,
long int n,
const void *new_element)
{
objects_list_node_t *node;
node = _objects_list_nth_node (list, n);
if (node != NULL)
{
objects_retain (objects_list_element_callbacks (list), new_element, list);
objects_release (objects_list_element_callbacks (list),
(void*)node->element,
list);
node->element = new_element;
}
return;
}
void
objects_list_replace_first_element (objects_list_t * list,
const void *new_element)
{
objects_list_replace_nth_element (list, 0, new_element);
return;
}
void
objects_list_replace_last_element (objects_list_t * list,
const void *new_element)
{
objects_list_replace_nth_element (list, -1, new_element);
return;
}
/** Creating **/
objects_list_t *
objects_list_alloc_with_allocs (objects_allocs_t allocs)
{
objects_list_t *list;
list = _objects_list_alloc_with_allocs (allocs);
return list;
}
objects_list_t *
objects_list_alloc (void)
{
return objects_list_alloc_with_allocs (objects_allocs_standard ());
}
objects_list_t *
objects_list (void)
{
return objects_list_init (objects_list_alloc ());
}
objects_list_t *
objects_list_with_allocs (objects_allocs_t allocs)
{
return objects_list_init (objects_list_alloc_with_allocs (allocs));
}
objects_list_t *
objects_list_with_allocs_with_callbacks (objects_allocs_t allocs,
objects_callbacks_t callbacks)
{
return objects_list_init_with_callbacks (objects_list_alloc_with_allocs (allocs),
callbacks);
}
objects_list_t *
objects_list_with_callbacks (objects_callbacks_t callbacks)
{
return objects_list_init_with_callbacks (objects_list_alloc (), callbacks);
}
objects_list_t *
objects_list_of_char_p (void)
{
return objects_list_with_callbacks (objects_callbacks_for_char_p);
}
objects_list_t *
objects_list_of_int (void)
{
return objects_list_with_callbacks (objects_callbacks_for_int);
}
objects_list_t *
objects_list_of_void_p (void)
{
return objects_list_with_callbacks (objects_callbacks_for_void_p);
}
objects_list_t *
objects_list_of_owned_void_p (void)
{
return objects_list_with_callbacks (objects_callbacks_for_owned_void_p);
}
objects_list_t *
objects_list_of_id (void)
{
return objects_list_with_callbacks (objects_callbacks_for_id);
}
/** Initializing **/
objects_list_t *
objects_list_init (objects_list_t * list)
{
return objects_list_init_with_callbacks (list, objects_callbacks_standard());
}
objects_list_t *
objects_list_init_with_callbacks (objects_list_t * list, objects_callbacks_t callbacks)
{
if (list != NULL)
{
list->callbacks = callbacks;
list->element_count = 0;
list->node_count = 0;
list->first_node = NULL;
list->last_node = NULL;
}
return list;
}
objects_list_t *
objects_list_init_from_list (objects_list_t * list, objects_list_t * old_list)
{
objects_list_enumerator_t enumerator;
const void *element;
if (list != NULL)
{
list->callbacks = objects_list_element_callbacks (old_list);
list->element_count = 0;
list->node_count = 0;
list->first_node = NULL;
list->last_node = NULL;
if (old_list != NULL)
{
/* Get a forward enumerator for OLD_LIST. */
enumerator = objects_list_forward_enumerator (old_list);
/* Walk from the beginning to the end of OLD_LIST, and add each
* element to the end of LIST. */
while (objects_list_enumerator_next_element (&enumerator, &element))
objects_list_at_index_insert_element (list, -1, element);
}
}
return list;
}
/** Destroying **/
void
objects_list_dealloc (objects_list_t * list)
{
/* Empty LIST out. */
objects_list_empty (list);
/* Get rid of LIST. */
_objects_list_dealloc (list);
return;
}
/** Comparing **/
int
objects_list_is_equal_to_list (objects_list_t * list, objects_list_t * other_list)
{
/* FIXME: Code this. */
return 0;
}
/** Concatenating **/
objects_list_t *
objects_list_append_list (objects_list_t * base_list, objects_list_t * suffix_list)
{
return objects_list_at_index_insert_list (base_list, -1, suffix_list);
}
objects_list_t *
objects_list_prepend_list (objects_list_t * base_list, objects_list_t * prefix_list)
{
return objects_list_at_index_insert_list (base_list, 0, prefix_list);
}
/* FIXME: I was lazy when I wrote this next one. It can easily be
* sped up. Do it. */
objects_list_t *
objects_list_at_index_insert_list (objects_list_t * base_list,
long int n,
objects_list_t * infix_list)
{
objects_list_enumerator_t enumerator;
const void *element;
if (n < 0)
enumerator = objects_list_forward_enumerator (infix_list);
else /* (n >= 0) */
enumerator = objects_list_reverse_enumerator (infix_list);
while (objects_list_enumerator_next_element (&enumerator, &element))
objects_list_at_index_insert_element (base_list, n, element);
return base_list;
}
/** Copying **/
objects_list_t *
objects_list_copy (objects_list_t * old_list)
{
/* FIXME: Should I be using `objects_allocs_standard()' or
* `objects_list_allocs(old_list)'? */
return objects_list_copy_with_allocs (old_list, objects_list_allocs (old_list));
}
objects_list_t *
objects_list_copy_with_allocs (objects_list_t * old_list, objects_allocs_t allocs)
{
objects_list_t *list;
/* Allocate a new (low-level) copy of OLD_LIST. */
list = _objects_list_copy_with_allocs (old_list, allocs);
/* Fill it in. */
return objects_list_init_from_list (list, old_list);
}
/** Mapping **/
objects_list_t *
objects_list_map_elements (objects_list_t * list,
const void *(*fcn) (const void *, const void *),
const void *user_data)
{
objects_list_enumerator_t enumerator;
objects_list_node_t *node;
enumerator = objects_list_enumerator (list);
while ((node = _objects_list_enumerator_next_node (&enumerator)) != NULL)
{
const void *element;
element = (*fcn) (node->element, user_data);
/* NOTE: I'm accessing the callbacks directly for a little
* efficiency. */
objects_retain (list->callbacks, element, list);
objects_release (list->callbacks, (void*)node->element, list);
node->element = element;
}
return list;
}
/** Creating other collections from lists **/
objects_hash_t *
objects_hash_init_from_list (objects_hash_t * hash, objects_list_t * list)
{
if (hash != NULL)
{
objects_list_enumerator_t enumerator;
const void *element;
/* Make a note of the callbacks for HASH. */
hash->callbacks = objects_list_element_callbacks (list);
/* Zero out the various counts. */
hash->node_count = 0;
hash->bucket_count = 0;
hash->element_count = 0;
/* Zero out the pointers. */
hash->first_node = NULL;
hash->buckets = NULL;
/* Resize HASH to the given CAPACITY. */
objects_hash_resize (hash, objects_list_capacity (list));
/* Get an element enumerator for LIST. */
enumerator = objects_list_enumerator (list);
/* Add LIST's elements to HASH, one at a time. Note that if LIST
* contains multiple elements from the same equivalence class, it
* is indeterminate which will end up in HASH. But this shouldn't
* be a problem. */
while (objects_list_enumerator_next_element (&enumerator, &element))
objects_hash_add_element (hash, element);
}
/* Return the newly initialized HASH. */
return hash;
}
// objects_chash_t *
// objects_chash_init_from_list (objects_chash_t * chash, objects_list_t * list)
// {
// if (chash != NULL)
// {
// objects_list_enumerator_t enumerator;
// const void *element;
//
// /* Make a note of the callbacks for CHASH. */
// chash->callbacks = objects_list_element_callbacks (list);
//
// /* Zero out the various counts. */
// chash->node_count = 0;
// chash->bucket_count = 0;
// chash->element_count = 0;
//
// /* Zero out the pointers. */
// chash->first_node = NULL;
// chash->buckets = NULL;
//
// /* Resize CHASH to the given CAPACITY. */
// objects_chash_resize (chash, objects_list_capacity (list));
//
// /* Get an element enumerator for LIST. */
// enumerator = objects_list_enumerator (list);
//
// /* Add LIST's elements to CHASH, one at a time. Note that if LIST
// * contains multiple elements from the same equivalence class, it
// * is indeterminate which will end up in CHASH. But this shouldn't
// * be a problem. */
// while (objects_list_enumerator_next_element (&enumerator, &element))
// objects_chash_add_element (chash, element);
// }
//
// /* Return the newly initialized CHASH. */
// return chash;
// }

File diff suppressed because it is too large Load diff

View file

@ -1,59 +0,0 @@
/* Structure counters and functions for getting at them.
* Copyright (C) 1995, 1996 Free Software Foundation, Inc.
*
* Author: Albin L. Jones <Albin.L.Jones@Dartmouth.EDU>
* Created: Sun Dec 3 00:23:13 EST 1995
* Updated: Sat Feb 10 13:52:15 EST 1996
* Serial: 96.02.10.01
*
* This file is part of the GNU Objective C Class Library.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the Free
* Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*
*/
/**** Included Headers *******************************************************/
#include <objects/number.h>
/**** Type, Constant, and Macro Definitions **********************************/
size_t ___objects_number_allocated = 0;
size_t ___objects_number_deallocated = 0;
size_t ___objects_number_serial = 0;
/**** Function Implementations ***********************************************/
/* Returns the number of Libobjects structures allocated. */
size_t
objects_number_allocated(void)
{
return ___objects_number_allocated;
}
/* Returns the number of Libobjects structures deallocated. */
size_t
objects_number_deallocated(void)
{
return ___objects_number_deallocated;
}
/* Returns the next serial number to be handed out. */
size_t
objects_number_serial(void)
{
return ___objects_number_serial;
}

View file

@ -1,41 +0,0 @@
/* A hookable abort function for Libobjects.
* Copyright (C) 1993, 1994, 1995, 1996 Free Software Foundation, Inc.
*
* Author: Albin L. Jones <Albin.L.Jones@Dartmouth.EDU>
* Created: Sat Feb 10 12:34:27 EST 1996
* Updated: Sat Feb 10 15:49:43 EST 1996
* Serial: 96.02.10.03
*
* This file is part of the GNU Objective C Class Library.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the Free
* Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*
*/
#ifndef __abort_h_OBJECTS_INCLUDE
#define __abort_h_OBJECTS_INCLUDE 1
/**** Included Headers *******************************************************/
/**** Type, Constant, and Macro Definitions **********************************/
extern void (*__objects_abort) (void);
/**** Function Prototypes ****************************************************/
void objects_abort (void);
#endif /* __abort_h_OBJECTS_INCLUDE */

View file

@ -1,82 +0,0 @@
/* Modular memory management. Better living through chemicals.
* Copyright (C) 1994, 1995, 1996 Free Software Foundation, Inc.
*
* Author: Albin L. Jones <Albin.L.Jones@Dartmouth.EDU>
* Created: Thu Oct 13 23:46:02 EDT 1994
* Updated: Sat Feb 10 15:47:25 EST 1996
* Serial: 96.02.10.01
*
* This file is part of the GNU Objective C Class Library.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the Free
* Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*
*/
#ifndef __allocs_h_OBJECTS_INCLUDE
#define __allocs_h_OBJECTS_INCLUDE 1
/**** Included Headers *******************************************************/
#include <stdlib.h>
/**** Type, Constant, and Macro Definitions **********************************/
typedef void *(*objects_malloc_func_t) (size_t, const void *);
typedef void *(*objects_calloc_func_t) (size_t, size_t, const void *);
typedef void *(*objects_realloc_func_t) (void *, size_t, const void *);
typedef void (*objects_free_func_t) (void *, const void *);
typedef struct _objects_allocs objects_allocs_t;
struct _objects_allocs
{
objects_malloc_func_t malloc;
objects_calloc_func_t calloc;
objects_realloc_func_t realloc;
objects_free_func_t free;
const void *user_data;
};
/* Shorthand macros. */
#define OBJECTS_MALLOC(S) objects_malloc(objects_standard_allocs(), (S))
#define OBJECTS_CALLOC(N, S) objects_calloc(objects_standard_allocs(), (N), (S))
#define OBJECTS_REALLOC(P, S) objects_realloc(objects_standard_allocs(), (P), (S))
#define OBJECTS_FREE(P) objects_free(objects_standard_allocs(), (P))
/* Change these if you need different default allocs. */
extern objects_allocs_t __objects_allocs_standard;
/**** Function Prototypes ****************************************************/
/* Returns `__objects_allocs_standard', defined above. */
objects_allocs_t
objects_allocs_standard (void);
void *
objects_malloc (objects_allocs_t allocs, size_t s);
void *
objects_calloc (objects_allocs_t allocs, size_t n, size_t s);
void *
objects_realloc (objects_allocs_t allocs, const void *p, size_t s);
void
objects_free (objects_allocs_t allocs, const void *p);
size_t
objects_next_power_of_two (size_t start);
#endif /* __allocs_h_OBJECTS_INCLUDE */

View file

@ -1,10 +1,10 @@
/* A sparse array for use with Libobjects.
/* A sparse array structure.
* Copyright (C) 1994, 1995, 1996 Free Software Foundation, Inc.
*
* Author: Albin L. Jones <Albin.L.Jones@Dartmouth.EDU>
* Created: Thu Mar 2 02:30:02 EST 1994
* Updated: Sat Feb 10 15:38:58 EST 1996
* Serial: 96.02.10.01
* Updated: Tue Mar 12 02:42:54 EST 1996
* Serial: 96.03.12.13
*
* This file is part of the GNU Objective C Class Library.
*
@ -20,9 +20,7 @@
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the Free
* Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*
*/
* Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
#ifndef __array_h_OBJECTS_INCLUDE
#define __array_h_OBJECTS_INCLUDE 1
@ -30,7 +28,7 @@
/**** Included Headers *******************************************************/
#include <stdlib.h>
#include <objects/allocs.h>
#include <Foundation/NSZone.h>
#include <objects/callbacks.h>
#include <objects/hash.h>
@ -42,157 +40,209 @@ typedef objects_array_bucket_t *objects_array_slot_t;
typedef struct _objects_array_enumerator objects_array_enumerator_t;
struct _objects_array_bucket
{
/* The bucket's real (or external) index */
size_t index;
{
/* The bucket's real (or external) index */
size_t index;
/* The bucket's cargo */
const void *element;
};
/* The bucket's cargo */
const void *element;
};
struct _objects_array
{
/* Identifying information. */
int magic;
size_t number;
const char *name;
const void *extra;
objects_callbacks_t extra_callbacks;
objects_allocs_t allocs;
{
/* Identifying information. */
int magic_number;
size_t serial_number;
NSZone *zone;
NSString *name;
const void *extra;
objects_callbacks_t extra_callbacks;
/* Callbacks for the items in the array. */
objects_callbacks_t callbacks;
/* Callbacks for the items in the array. */
objects_callbacks_t callbacks;
/* Internal counters */
size_t slot_count;
size_t element_count;
/* Internal counters */
size_t slot_count;
size_t element_count;
/* Databanks */
objects_array_slot_t *slots;
objects_array_slot_t *sorted_slots;
};
/* Databanks */
objects_array_slot_t *slots;
objects_array_slot_t *sorted_slots;
};
struct _objects_array_enumerator
{
objects_array_t * array;
size_t index;
int is_sorted;
int is_ascending;
};
{
objects_array_t *array;
size_t index;
int is_sorted;
int is_ascending;
};
/**** Function Prototypes ****************************************************/
/** Basics **/
#include <objects/array-basics.h>
#include <objects/array-callbacks.h>
#include <objects/array-bas.h>
#include <objects/array-cbs.h>
/** Creating **/
objects_array_t * objects_array_alloc (void);
objects_array_t *
objects_array_alloc(void);
objects_array_t * objects_array_alloc_with_allocs (objects_allocs_t allocs);
objects_array_t *
objects_array_alloc_with_zone(NSZone *zone);
objects_array_t * objects_array (void);
objects_array_t *
objects_array(void);
objects_array_t * objects_array_with_allocs (objects_allocs_t allocs);
objects_array_t *
objects_array_with_zone(NSZone *zone);
objects_array_t * objects_array_with_allocs_with_callbacks (objects_allocs_t allocs, objects_callbacks_t callbacks);
objects_array_t *
objects_array_with_zone_with_callbacks(NSZone *zone,
objects_callbacks_t callbacks);
objects_array_t * objects_array_with_callbacks (objects_callbacks_t callbacks);
objects_array_t *
objects_array_with_callbacks(objects_callbacks_t callbacks);
objects_array_t * objects_array_of_char_p (void);
objects_array_t *
objects_array_of_char_p(void);
objects_array_t * objects_array_of_void_p (void);
objects_array_t *
objects_array_of_non_owned_void_p(void);
objects_array_t * objects_array_of_owned_void_p (void);
objects_array_t *
objects_array_of_owned_void_p(void);
objects_array_t * objects_array_of_int (void);
objects_array_t *
objects_array_of_int(void);
objects_array_t * objects_array_of_id (void);
objects_array_t *
objects_array_of_id(void);
/** Initializing **/
objects_array_t * objects_array_init (objects_array_t * array);
objects_array_t *
objects_array_init(objects_array_t *array);
objects_array_t * objects_array_init_with_callbacks (objects_array_t * array, objects_callbacks_t callbacks);
objects_array_t *
objects_array_init_with_callbacks(objects_array_t *array,
objects_callbacks_t callbacks);
objects_array_t * objects_array_init_with_array (objects_array_t * array, objects_array_t * other_array);
objects_array_t *
objects_array_init_with_array(objects_array_t *array,
objects_array_t *other_array);
/** Copying **/
objects_array_t * objects_array_copy (objects_array_t * array);
objects_array_t *
objects_array_copy(objects_array_t *array);
objects_array_t * objects_array_copy_with_allocs (objects_array_t * array, objects_allocs_t allocs);
objects_array_t *
objects_array_copy_with_zone(objects_array_t *array, NSZone *zone);
/** Destroying **/
void objects_array_dealloc (objects_array_t * array);
void
objects_array_dealloc(objects_array_t *array);
/** Comparing **/
int objects_array_is_equal_to_array (objects_array_t * array, objects_array_t * other_array);
int
objects_array_is_equal_to_array(objects_array_t *array,
objects_array_t *other_array);
/** Adding **/
const void *objects_array_at_index_put_element (objects_array_t * array, size_t index, const void *element);
const void *
objects_array_at_index_put_element(objects_array_t *array,
size_t index,
const void *element);
/** Replacing **/
/** Removing **/
void objects_array_remove_element_at_index (objects_array_t * array, size_t index);
void
objects_array_remove_element_at_index(objects_array_t *array, size_t index);
void objects_array_remove_element (objects_array_t * array, const void *element);
void
objects_array_remove_element(objects_array_t *array, const void *element);
void objects_array_remove_element_known_present (objects_array_t * array, const void *element);
void
objects_array_remove_element_known_present(objects_array_t *array,
const void *element);
/** Emptying **/
void objects_array_empty (objects_array_t * array);
void
objects_array_empty(objects_array_t *array);
/** Searching **/
int objects_array_contains_element (objects_array_t * array, const void *element);
int
objects_array_contains_element(objects_array_t *array, const void *element);
const void *objects_array_element (objects_array_t * array, const void *element);
const void *
objects_array_element(objects_array_t *array, const void *element);
size_t objects_array_index_of_element (objects_array_t * array, const void *element);
size_t
objects_array_index_of_element(objects_array_t *array, const void *element);
const void *objects_array_element_at_index (objects_array_t * array, size_t index);
const void *
objects_array_element_at_index(objects_array_t *array, size_t index);
const void **objects_array_all_elements (objects_array_t * array);
const void **
objects_array_all_elements(objects_array_t *array);
const void **objects_array_all_elements_ascending (objects_array_t * array);
const void **
objects_array_all_elements_ascending(objects_array_t *array);
const void **objects_array_all_element_descending (objects_array_t * array);
const void **
objects_array_all_element_descending(objects_array_t *array);
/** Enumerating **/
objects_array_enumerator_t objects_array_enumerator (objects_array_t * array);
objects_array_enumerator_t
objects_array_enumerator(objects_array_t *array);
objects_array_enumerator_t objects_array_ascending_enumerator (objects_array_t * array);
objects_array_enumerator_t
objects_array_ascending_enumerator(objects_array_t *array);
objects_array_enumerator_t objects_array_descending_enumerator (objects_array_t * array);
objects_array_enumerator_t
objects_array_descending_enumerator(objects_array_t *array);
int objects_array_enumerator_next_index_and_element (objects_array_enumerator_t *enumerator, size_t *index, const void **element);
int
objects_array_enumerator_next_index_and_element(objects_array_enumerator_t *enumerator,
size_t *index,
const void **element);
int objects_array_enumerator_next_element (objects_array_enumerator_t *enumerator, const void **element);
int
objects_array_enumerator_next_element(objects_array_enumerator_t *enumerator,
const void **element);
int objects_array_enumerator_next_index (objects_array_enumerator_t *enumerator, size_t *element);
int
objects_array_enumerator_next_index(objects_array_enumerator_t *enumerator,
size_t *element);
/** Statistics **/
int objects_array_is_empty (objects_array_t * array);
int
objects_array_is_empty(objects_array_t *array);
size_t objects_array_count (objects_array_t * array);
size_t
objects_array_count(objects_array_t *array);
size_t objects_array_capacity (objects_array_t * array);
size_t
objects_array_capacity(objects_array_t *array);
int objects_array_check (objects_array_t * array);
int
objects_array_check(objects_array_t *array);
/** Miscellaneous **/
objects_hash_t *objects_hash_init_from_array (objects_hash_t *hash, objects_array_t *array);
objects_hash_t *
objects_hash_init_from_array(objects_hash_t *hash, objects_array_t *array);
#endif /* __array_h_OBJECTS_INCLUDE */

View file

@ -1,59 +0,0 @@
/* Macros for bit-wise operations.
* Copyright (C) 1996 Free Software Foundation, Inc.
*
* Author: Albin L. Jones <Albin.L.Jones@Dartmouth.EDU>
* Created: Sat Feb 10 21:17:10 EST 1996
* Updated: Sat Feb 10 21:17:10 EST 1996
* Serial: 96.02.10.01
*
* This file is part of the GNU Objective C Class Library.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the Free
* Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*
*/
/**** Included Headers *******************************************************/
#include <objects/callbacks.h>
/**** Type, Constant, and Macro Definitions **********************************/
/**** Function Implementations ***********************************************/
#ifndef __bits_h_OBJECTS_INCLUDE
#define __bits_h_OBJECTS_INCLUDE 1
/**** Included Headers *******************************************************/
/**** Type, Constant, and Macro Definitions **********************************/
/** Bit operations **/
/* Set the Nth bit of V to one. */
#define OBJECTS_BIT_POKE(V,N) ((V) |= (1 << (N)))
/* Set the Nth bit of V to zero. */
#define OBJECTS_BIT_NOCK(V,N) ((V) &= ~(1 << (N)))
/* Toggle the Nth bit of V. */
#define OBJECTS_BIT_PLUK(V,N) ((V) ^= (1 << (N)))
/* Grab the Nth bit of V. */
#define OBJECTS_BIT_PEEK(V,N) ((V) & (1 << (N)))
/**** Function Prototypes ****************************************************/
#endif /* __bits_h_OBJECTS_INCLUDE */

View file

@ -3,8 +3,8 @@
*
* Author: Albin L. Jones <Albin.L.Jones@Dartmouth.EDU>
* Created: Sun Oct 9 13:18:50 EDT 1994
* Updated: Sun Feb 11 01:46:03 EST 1996
* Serial: 96.02.11.01
* Updated: Mon Mar 11 00:31:13 EST 1996
* Serial: 96.03.11.01
*
* This file is part of the GNU Objective C Class Library.
*
@ -20,9 +20,7 @@
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the Free
* Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*
*/
* Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
#ifndef __callbacks_h_OBJECTS_INCLUDE
#define __callbacks_h_OBJECTS_INCLUDE 1
@ -30,17 +28,16 @@
/**** Included Headers *******************************************************/
#include <stdlib.h>
#include <Foundation/NSString.h>
/**** Type, Constant, and Macro Definitions **********************************/
typedef size_t (*objects_hash_func_t) (const void *, const void *);
typedef int (*objects_compare_func_t) (const void *, const void *,
const void *);
typedef int (*objects_is_equal_func_t) (const void *, const void *,
const void *);
typedef void *(*objects_retain_func_t) (const void *, const void *);
typedef void (*objects_release_func_t) (void *, const void *);
typedef void *(*objects_describe_func_t) (const void *, const void *);
typedef size_t (*objects_hash_func_t)(const void *, void *);
typedef int (*objects_compare_func_t)(const void *, const void *, void *);
typedef int (*objects_is_equal_func_t)(const void *, const void *, void *);
typedef const void *(*objects_retain_func_t)(const void *, void *);
typedef void (*objects_release_func_t)(void *, void *);
typedef NSString *(*objects_describe_func_t)(const void *, void *);
typedef struct _objects_callbacks objects_callbacks_t;
@ -59,7 +56,7 @@ struct _objects_callbacks
extern const objects_callbacks_t objects_callbacks_for_int;
extern const objects_callbacks_t objects_callbacks_for_char_p;
extern const objects_callbacks_t objects_callbacks_for_void_p;
extern const objects_callbacks_t objects_callbacks_for_non_owned_void_p;
extern const objects_callbacks_t objects_callbacks_for_owned_void_p;
extern const objects_callbacks_t objects_callbacks_for_int_p;
extern const objects_callbacks_t objects_callbacks_for_id;
@ -78,97 +75,105 @@ extern objects_callbacks_t __objects_callbacks_standard;
/** Generic callbacks **/
/* Returns `__objects_callbacks_standard', defined above. */
/* Returns the programmer-alterable `__objects_callbacks_standard',
* defined above. */
objects_callbacks_t
objects_callbacks_standard (void);
objects_callbacks_standard(void);
/** Standardizing callbacks **/
/* Makes sure that enough of CALLBACKS is defined (i.e., non-zero)
* to be used. This is used, rather than local checks for usability,
* to improve the efficiency of callback use. */
objects_callbacks_t
objects_callbacks_standardize (objects_callbacks_t callbacks);
objects_callbacks_standardize(objects_callbacks_t callbacks);
/** Using callbacks **/
size_t objects_hash (objects_callbacks_t callbacks,
const void *thing,
const void *user_data);
size_t
objects_hash(objects_callbacks_t callbacks,
const void *thing,
void *user_data);
int objects_compare (objects_callbacks_t callbacks,
const void *thing1,
const void *thing2,
const void *user_data);
int
objects_compare(objects_callbacks_t callbacks,
const void *thing1,
const void *thing2,
void *user_data);
int objects_is_equal (objects_callbacks_t callbacks,
const void *thing1,
const void *thing2,
const void *user_data);
int
objects_is_equal(objects_callbacks_t callbacks,
const void *thing1,
const void *thing2,
void *user_data);
void *objects_retain (objects_callbacks_t callbacks,
const void *thing,
const void *user_data);
const void *
objects_retain(objects_callbacks_t callbacks,
const void *thing,
void *user_data);
void objects_release (objects_callbacks_t callbacks,
void *thing,
const void *user_data);
void
objects_release(objects_callbacks_t callbacks,
void *thing,
void *user_data);
/* FIXME: Decide what to do with this describe stuff. We'd really like
* them to return Strings? Or would we rather they be `char *'s?
* Or something else? */
void *objects_describe (objects_callbacks_t callbacks,
const void *thing,
const void *user_data);
NSString *
objects_describe(objects_callbacks_t callbacks,
const void *thing,
void *user_data);
const void *objects_not_an_item_marker (objects_callbacks_t);
const void *
objects_not_an_item_marker(objects_callbacks_t callbacks);
/** Specific callback functions **/
/** Specific callback functions... **/
/* For `void *' */
size_t objects_void_p_hash(const void *ptr);
int objects_void_p_compare(const void *ptr, const void *qtr);
int objects_void_p_is_equal(const void *ptr, const void *qtr);
const void *objects_void_p_retain(const void *ptr);
void objects_void_p_release(const void *ptr);
const void *objects_void_p_describe(const void *ptr);
/* For non-owned `void *' */
size_t objects_non_owned_void_p_hash(const void *ptr);
int objects_non_owned_void_p_compare(const void *ptr, const void *qtr);
int objects_non_owned_void_p_is_equal(const void *ptr, const void *qtr);
const void *objects_non_owned_void_p_retain(const void *ptr);
void objects_non_owned_void_p_release(void *ptr);
NSString *objects_non_owned_void_p_describe(const void *ptr);
/* For `void *' */
/* For owned `void *' */
size_t objects_owned_void_p_hash(const void *ptr);
int objects_owned_void_p_compare(const void *ptr, const void *qtr);
int objects_owned_void_p_is_equal(const void *ptr, const void *qtr);
const void *objects_owned_void_p_retain(const void *ptr);
void objects_owned_void_p_release(const void *ptr);
const void *objects_owned_void_p_describe(const void *ptr);
void objects_owned_void_p_release(void *ptr);
NSString *objects_owned_void_p_describe(const void *ptr);
/* For `int' */
size_t objects_int_hash(const void *i);
int objects_int_compare(const void *i, const void *j);
int objects_int_is_equal(const void *i, const void *j);
const void *objects_int_retain(const void *i);
void objects_int_release(const void *i);
const void *objects_int_describe(const void *i);
size_t objects_int_hash(int i);
int objects_int_compare(int i, int j);
int objects_int_is_equal(int i, int j);
const void *objects_int_retain(int i);
void objects_int_release(int i);
NSString *objects_int_describe(int i);
/* For `int *' */
size_t objects_int_p_hash(const void *iptr);
int objects_int_p_compare(const void *iptr, const void *jptr);
int objects_int_p_is_equal(const void *iptr, const void *jptr);
const void *objects_int_p_retain(const void *iptr);
void objects_int_p_release(const void *iptr);
const void *objects_int_p_describe(const void *iptr);
size_t objects_int_p_hash(const int *iptr);
int objects_int_p_compare(const int *iptr, const int *jptr);
int objects_int_p_is_equal(const int *iptr, const int *jptr);
const void *objects_int_p_retain(const int *iptr);
void objects_int_p_release(int *iptr);
NSString *objects_int_p_describe(const int *iptr);
/* For `char *' */
size_t objects_char_p_hash(const void *cptr);
int objects_char_p_compare(const void *cptr, const void *dptr);
int objects_char_p_is_equal(const void *cptr, const void *dptr);
const void *objects_char_p_retain(const void *cptr);
void objects_char_p_release(const void *cptr);
const void *objects_char_p_describe(const void *cptr);
size_t objects_char_p_hash(const char *cptr);
int objects_char_p_compare(const char *cptr, const char *dptr);
int objects_char_p_is_equal(const char *cptr, const char *dptr);
const void *objects_char_p_retain(const char *cptr);
void objects_char_p_release(char *cptr);
NSString *objects_char_p_describe(const char *cptr);
/* For `id' */
size_t objects_id_hash(const void *obj);
int objects_id_compare(const void *obj, const void *jbo);
int objects_id_is_equal(const void *obj, const void *jbo);
const void *objects_id_retain(const void *obj);
void objects_id_release(const void *obj);
const void *objects_id_describe(const void *obj);
size_t objects_id_hash(id obj);
int objects_id_compare(id obj, id jbo);
int objects_id_is_equal(id obj, id jbo);
const void *objects_id_retain(id obj);
void objects_id_release(id obj);
NSString *objects_id_describe(id obj);
#endif /* __callbacks_h_OBJECTS_INCLUDE */

View file

@ -20,9 +20,7 @@
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the Free
* Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*
*/
* Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
#ifndef __data_h_OBJECTS_INCLUDE
#define __data_h_OBJECTS_INCLUDE 1
@ -74,7 +72,7 @@ struct _objects_data
/** Basics **/
#include <objects/data-basics.h>
#include <objects/data-bas.h>
/** Hashing **/

View file

@ -1,10 +1,10 @@
/* A hash table for use with Libobjects.
/* A hash table.
* Copyright (C) 1993, 1994, 1995, 1996 Free Software Foundation, Inc.
*
* Author: Albin L. Jones <Albin.L.Jones@Dartmouth.EDU>
* Created: ??? ??? ?? ??:??:?? ??? 1993
* Updated: Sat Feb 10 15:35:37 EST 1996
* Serial: 96.02.10.01
* Updated: Tue Mar 19 00:25:34 EST 1996
* Serial: 96.03.19.05
*
* This file is part of the GNU Objective C Class Library.
*
@ -20,208 +20,374 @@
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the Free
* Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*
*/
* Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
#ifndef __hash_h_OBJECTS_INCLUDE
#define __hash_h_OBJECTS_INCLUDE 1
/**** Included Headers *******************************************************/
#include <objects/allocs.h>
#include <Foundation/NSZone.h>
#include <Foundation/NSString.h>
#include <objects/callbacks.h>
/**** Type, Constant, and Macro Definitions **********************************/
/* Need these up here because of their interdependence. */
typedef struct _objects_hash objects_hash_t;
typedef struct _objects_hash_bucket objects_hash_bucket_t;
typedef struct _objects_hash_node objects_hash_node_t;
typedef struct _objects_hash_enumerator objects_hash_enumerator_t;
typedef struct _objects_hash_node objects_hash_node_t;
typedef struct _objects_hash_bucket objects_hash_bucket_t;
/* Private type for elemental holding. */
struct _objects_hash_node
{
objects_hash_t *hash;
objects_hash_bucket_t *bucket;
{
/* The hash table with which the node is associated. */
objects_hash_t *hash;
objects_hash_node_t *next_in_bucket;
objects_hash_node_t *prev_in_bucket;
objects_hash_node_t *next_in_hash;
objects_hash_node_t *prev_in_hash;
/* The bucket in HASH in which the node sits. */
objects_hash_bucket_t *bucket;
const void *element;
};
/* These hold the BUCKET linked list together. */
objects_hash_node_t *next_in_bucket;
objects_hash_node_t *prev_in_bucket;
/* For enumerating over the whole hash table. These make
* enumerating much quicker. They also make it safer. */
objects_hash_node_t *next_in_hash;
objects_hash_node_t *prev_in_hash;
/* What the node is holding for us. Its raison d'etre. */
const void *element;
};
/* Private type for holding chains of nodes. */
struct _objects_hash_bucket
{
size_t node_count;
size_t element_count;
{
/* The number of nodes in this bucket. For internal consistency checks. */
size_t node_count;
objects_hash_node_t *first_node;
};
/* The number of elements in this bucket. (This had *better* be
* the same as NODE_COUNT, or something's wrong.) */
size_t element_count;
/* The head of this bucket's linked list of nodes. */
objects_hash_node_t *first_node;
};
/* The hash table type. */
struct _objects_hash
{
int magic;
size_t number;
const char *name;
const void *extra;
objects_callbacks_t extra_callbacks;
objects_allocs_t allocs;
{
/* All structures have these...
* And all structures have them in the same order. */
int magic_number;
size_t serial_number;
NSZone *zone;
NSString *name;
const void *extra;
objects_callbacks_t extra_callbacks;
/* Callbacks for the items in the hash. */
objects_callbacks_t callbacks;
/* Callbacks for the elements of the hash. */
objects_callbacks_t callbacks;
/* Internal hash counters. */
size_t bucket_count; /* How many types of items? */
size_t node_count; /* How many items? */
size_t element_count; /* How many elements? */
/* Internal counters. Mainly for consistency's sake. */
size_t bucket_count; /* How many types of items? */
size_t node_count; /* How many items? */
size_t element_count; /* How many elements? */
/* Places to start looking for elements. */
objects_hash_bucket_t *buckets;
objects_hash_node_t *first_node;
};
/* Places to start looking for elements. */
objects_hash_bucket_t *buckets; /* Organized as a hash. */
objects_hash_node_t *first_node; /* Organized as a linked list.
* (For enumerating...) */
};
/* Type for enumerating the elements of a hash table. */
struct _objects_hash_enumerator
{
objects_hash_t *hash;
objects_hash_node_t *node;
};
{
objects_hash_t *hash; /* To which hash do I belong? */
objects_hash_node_t *node; /* Which node is next? */
};
/**** Function Prototypes ****************************************************/
/** Basics **/
/** Basics... **/
#include <objects/hash-basics.h>
#include <objects/hash-callbacks.h>
/* All the structures (hashes, maps, lists, and arrays) have
* the same basic ideas behind them. */
/** Hashing **/
#include <objects/hash-bas.h>
#include <objects/hash-cbs.h>
size_t objects_hash_hash (objects_hash_t * hash);
/** Callbacks... **/
/** Creating **/
/* Returns a collection of callbacks for use with hash tables. */
objects_callbacks_t
objects_callbacks_for_hash(void);
objects_hash_t * objects_hash_alloc (void);
/** Creating... **/
objects_hash_t * objects_hash_alloc_with_allocs (objects_allocs_t alloc);
/* Allocate a hash table in the default zone. */
objects_hash_t *
objects_hash_alloc(void);
objects_hash_t * objects_hash_with_callbacks (objects_callbacks_t callbacks);
/* Allocate a hash table in the memory block ZONE. */
objects_hash_t *
objects_hash_alloc_with_zone(NSZone *zone);
objects_hash_t * objects_hash_with_allocs (objects_allocs_t allocs);
/* Create an empty hash table in the memory block ZONE. The returned
* hash table has a "reasonable" default capacity, but will need to
* be resized to suit your specific needs if more than a couple of
* dozen elements will be placed within it. */
objects_hash_t *
objects_hash_with_zone_with_callbacks(NSZone *zone,
objects_callbacks_t callbacks);
objects_hash_t * objects_hash_with_allocs_with_callbacks (objects_allocs_t allocs, objects_callbacks_t callbacks);
/* Like calling 'objects_hash_with_zone_with_callbacks(zone,
* objects_callbacks_standard())'. */
objects_hash_t *
objects_hash_with_zone(NSZone *zone);
objects_hash_t * objects_hash_of_char_p (void);
/* Like calling 'objects_hash_with_zone_with_callbacks(0, callbacks)'. */
objects_hash_t *
objects_hash_with_callbacks(objects_callbacks_t callbacks);
objects_hash_t * objects_hash_of_void_p (void);
/* These are just shortcuts for ease of use. */
objects_hash_t *objects_hash_of_char_p(void);
objects_hash_t *objects_hash_of_non_owned_void_p(void);
objects_hash_t *objects_hash_of_owned_void_p(void);
objects_hash_t *objects_hash_of_int(void);
objects_hash_t *objects_hash_of_int_p(void);
objects_hash_t *objects_hash_of_id(void);
objects_hash_t * objects_hash_of_owned_void_p (void);
/** Initializing... **/
objects_hash_t * objects_hash_of_int (void);
/* Initializes HASH with a "reasonable" capacity, with the
* callbacks obtained from 'objects_callbacks_standard()'. */
objects_hash_t *
objects_hash_init(objects_hash_t *hash);
objects_hash_t * objects_hash_of_id (void);
/* Initializes HASH with a "reasonable" capacity and
* with element callbacks CALLBACKS. */
objects_hash_t *
objects_hash_init_with_callbacks(objects_hash_t *hash,
objects_callbacks_t callbacks);
/** Initializing **/
/* Initializes HASH with the capacity, callbacks, and contents
* of OTHER_HASH. NOTE: This is (as it must be) a "shallow" copying.
* See 'objects_hash_copy_with_zone()', below. */
objects_hash_t *
objects_hash_init_with_hash(objects_hash_t *hash,
objects_hash_t *other_hash);
objects_hash_t * objects_hash_init (objects_hash_t * hash);
/** Copying... **/
objects_hash_t * objects_hash_init_with_callbacks (objects_hash_t * hash, objects_callbacks_t callbacks);
/* Creates a (shallow) copy of HASH in the memory block ZONE. WARNING:
* If the elements of HASH are pointers to mutable items, it is the
* programmer's responsibility to deepen the copy returned by this
* function call (using, for example, `objects_hash_map_elements()'). */
objects_hash_t *
objects_hash_copy_with_zone(objects_hash_t *hash, NSZone *zone);
objects_hash_t * objects_hash_init_with_hash (objects_hash_t * hash, objects_hash_t * other_hash);
/* Create a (shallow) copy of HASH in the default zone. WARNING: See the
* above function for an important caveat about copying. */
objects_hash_t *
objects_hash_copy(objects_hash_t *old_hash);
/** Copying **/
objects_hash_t * objects_hash_copy (objects_hash_t * old_hash);
objects_hash_t * objects_hash_copy_with_allocs (objects_hash_t * hash, objects_allocs_t new_allocs);
/** Mapping **/
/** Mapping... **/
/* WARNING: The mapping function FCN must be one-to-one on elements of
* HASH. I.e., for reasons of efficiency, `objects_hash_map_elements()'
* makes no provision for the possibility that FCN maps two unequal
* elements of HASH to the same (or equal) elements. The better way
* elements of HASH to the same (or "equal") elements. The better way
* to handle functions that aren't one-to-one is to create a new hash
* and transform the elements of the first to create the elements of
* the second. */
objects_hash_t *
objects_hash_map_elements (objects_hash_t * hash,
const void *(*fcn) (const void *, const void *),
const void *user_data);
* the second (by manual enumeration). */
objects_hash_t *
objects_hash_map_elements(objects_hash_t *hash,
const void *(*fcn)(const void *, const void *),
const void *user_data);
/** Destroying **/
/** Destroying... **/
void objects_hash_dealloc (objects_hash_t * hash);
/* Releases all the elements of HASH, and then frees up the space
* HASH used. HASH is no longer a (pointer to a) valid hash
* table structure after this call. */
void
objects_hash_dealloc(objects_hash_t *hash);
/** Comparing **/
/** Comparing... **/
int objects_hash_contains_hash (objects_hash_t * hash, objects_hash_t * other_hash);
/* Returns 'true' if every element of OTHER_HASH is also
* a member of HASH. Otherwise, returns 'false'. */
int
objects_hash_contains_hash(objects_hash_t *hash,
objects_hash_t *other_hash);
int objects_hash_intersects_hash (objects_hash_t * hash, objects_hash_t * other_hash);
/* Returns 'true' if some element of HASH is also
* a member of OTHER_HASH. Otherwise, returns 'false'. */
int
objects_hash_intersects_hash(objects_hash_t *hash,
objects_hash_t *other_hash);
int objects_hash_is_equal_to_hash (objects_hash_t * hash, objects_hash_t * other_hash);
/* Returns 'true' if HASH and OTHER_HASH have the same number of elements,
* HASH contains OTHER_HASH, and OTHER_HASH contains HASH. Otheraise, returns 'false'. */
int
objects_hash_is_equal_to_hash(objects_hash_t *hash,
objects_hash_t *other_hash);
/** Adding **/
/** Adding... **/
const void *objects_hash_add_element_known_absent (objects_hash_t *hash,
const void *element);
/* Adds ELEMENT to HASH. If ELEMENT is "equal" to an item already in HASH,
* then we abort. If ELEMENT is the "not an element marker" for HASH,
* then we abort. [NOTE: This abortive behaviour will be changed in a
* future revision.] */
const void *
objects_hash_add_element_known_absent(objects_hash_t *hash,
const void *element);
const void *objects_hash_add_element (objects_hash_t *hash,
const void *element);
/* Adds ELEMENT to HASH. If ELEMENT is "equal" to an item already in HASH,
* then that older item is released using the 'release()' callback function
* that was specified when HASH was created. (If ELEMENT is the "not an
* element marker" for HASH, then all bets are off, and we abort.
* [NOTE: This abortive behaviour will be changed in a future revision.]) */
const void *
objects_hash_add_element(objects_hash_t *hash, const void *element);
const void *objects_hash_add_element_if_absent (objects_hash_t *hash,
const void *element);
/* If (any item "equal" to) ELEMENT is in HASH, then that member of HASH is
* returned. Otherwise, the "not an element marker" for HASH is returned
* and ELEMENT is added to HASH. If ELEMENT is the "not an element marker"
* for HASH, then we abort. [NOTE: This abortive behaviour will be changed
* in a future revision.] */
const void *
objects_hash_add_element_if_absent(objects_hash_t *hash, const void *element);
/** Replacing **/
/** Replacing... **/
void objects_hash_replace_element (objects_hash_t *hash, const void *element);
/* If (some item "equal" to) ELEMENT is an element of HASH, then ELEMENT is
* substituted for it. The old element is released. (This is rather
* like the non-existant but perfectly reasonable function
* 'objects_hash_add_element_if_present()'.) */
void
objects_hash_replace_element(objects_hash_t *hash,
const void *element);
/** Removing **/
/** Removing... **/
void objects_hash_remove_element (objects_hash_t *hash, const void *element);
/* Removes the element (if any) of HASH which is "equal" to ELEMENT,
* according to HASH's element callbacks. It is not an error to
* remove ELEMENT from HASH, if no element of HASH is "equal" to ELEMENT. */
void
objects_hash_remove_element(objects_hash_t *hash, const void *element);
/** Emptying **/
/** Emptying... **/
void objects_hash_empty (objects_hash_t *hash);
/* Empties HASH, releasing all of its elements while retaining
* its current "capacity". */
void
objects_hash_empty(objects_hash_t *hash);
/** Searching **/
/** Searching... **/
void *objects_hash_any_element (objects_hash_t *hash);
/* Returns a "random" element of HASH, for your viewing enjoyment. */
void *
objects_hash_any_element(objects_hash_t *hash);
int objects_hash_contains_element (objects_hash_t *hash, const void *element);
/* Returns `true' if some element of HASH is "equal" to ELEMENT,
* according to HASH's element callbacks. */
int
objects_hash_contains_element(objects_hash_t *hash, const void *element);
const void *objects_hash_element (objects_hash_t *hash, const void *element);
/* Returns the element of HASH (or the appropriate `not an element
* marker' if there is none) which is "equal" to ELEMENT. */
const void *
objects_hash_element(objects_hash_t *hash, const void *element);
const void **objects_hash_all_elements (objects_hash_t *hash);
/* Returns an array with all the elements of HASH, terminated
* by HASH's "not an element marker". It is your responsibility
* to free the returned array. [NOTE: this responsibility may
* shift from your shoulders in a later revision.] */
const void **
objects_hash_all_elements(objects_hash_t *hash);
/** Enumerating **/
/** Enumerating... **/
objects_hash_enumerator_t objects_hash_enumerator (objects_hash_t *hash);
/* Returns an enumerator for HASH's elements. WARNING: DO NOT ALTER
* A HASH DURING AN ENUMERATION. DOING SO WILL PROBABLY LEAVE YOUR ENUMERATION
* IN AN INDETERMINATE STATE. If you are hell-bent on ignoring the above
* warning, please check out the source code for some more specific
* information about when and how one can get away with it. */
objects_hash_enumerator_t
objects_hash_enumerator_for_hash(objects_hash_t *hash);
int objects_hash_enumerator_next_element (objects_hash_enumerator_t *enumeratr,
const void **element);
/* Returns `false' if the enumeration is complete, `true' otherwise.
* If ELEMENT is non-zero, the next element of ENUMERATOR's hash table
* is returned by reference. */
int
objects_hash_enumerator_next_element(objects_hash_enumerator_t *enumerator,
const void **element);
/** Statistics **/
/** Statistics... **/
int objects_hash_is_empty (objects_hash_t * hash);
/* Returns `true' if HASH contains no elements. */
int
objects_hash_is_empty(objects_hash_t *hash);
size_t objects_hash_count (objects_hash_t * hash);
/* Returns the number of elements HASH is currently holding. So long as no
* additions or removals occur, you may take this number to be accurate. */
size_t
objects_hash_count(objects_hash_t *hash);
size_t objects_hash_capacity (objects_hash_t * hash);
/* Returns a number which represents (to some degree) HASH's current ability
* to hold stuff. Do not, however, rely on this for precision. Treat as
* a (reasonable) estimate. */
size_t
objects_hash_capacity(objects_hash_t *hash);
int objects_hash_check (objects_hash_t * hash);
/* Performs an internal consistency check on HASH. Useful only
* for debugging. */
int
objects_hash_check(objects_hash_t *hash);
/** Miscellaneous **/
/** Resizing... **/
size_t objects_hash_resize (objects_hash_t * hash, size_t new_capacity);
/* Resizes HASH to be ready to contain (at least) NEW_CAPACITY many elements.
* However, as far as you are concerned, it is indeterminate what exactly
* this means. After receiving and successfully processing this call,
* you are *not* guaranteed that HASH has actually set aside space for
* NEW_CAPACITY elements, for example. All that you are guaranteed is that,
* to the best of its ability, HASH will incur no loss in efficiency so long
* as it contains no more than NEW_CAPACITY elements. */
size_t
objects_hash_resize(objects_hash_t *hash, size_t new_capacity);
size_t objects_hash_rightsize (objects_hash_t * hash);
/* Shrinks (or grows) HASH to be comfortable with the number of elements
* it contains. In all likelyhood, after this call, HASH is more efficient
* in terms of its speed of search vs. use of space balance. */
size_t
objects_hash_rightsize(objects_hash_t *hash);
objects_hash_t * objects_hash_intersect_hash (objects_hash_t * hash, objects_hash_t * other_hash);
/** Describing... **/
objects_hash_t * objects_hash_minus_hash (objects_hash_t * hash, objects_hash_t * other_hash);
/* Returns a string describing (the contents of) HASH. */
NSString *
objects_hash_description(objects_hash_t *hash);
objects_hash_t * objects_hash_union_hash (objects_hash_t * hash, objects_hash_t * other_hash);
/** Set theoretic operations... **/
/* Removes from HASH all of its elements which are not also
* elements of OTHER_HASH. Returns HASH as a courtesy. */
objects_hash_t *
objects_hash_intersect_hash(objects_hash_t *hash, objects_hash_t *other_hash);
/* Removes from HASH all of its elements which are also
* elements of OTHER_HASH. Returns HASH as a courtesy. */
objects_hash_t *
objects_hash_minus_hash(objects_hash_t *hash, objects_hash_t *other_hash);
/* Adds to HASH all elements of OTHER_HASH which are not
* already members of HASH. Returns HASH as a courtesy. */
objects_hash_t *
objects_hash_union_hash(objects_hash_t *hash, objects_hash_t *other_hash);
#endif /* __hash_h_OBJECTS_INCLUDE */

View file

@ -1,10 +1,10 @@
/* A list for use with Libobjects.
/* A list structure.
* Copyright (C) 1995, 1996 Free Software Foundation, Inc.
*
* Author: Albin L. Jones <Albin.L.Jones@Dartmouth.EDU>
* Created: Tue Sep 5 17:25:59 EDT 1995
* Updated: Sat Feb 10 15:37:41 EST 1996
* Serial: 96.02.10.01
* Updated: Sun Mar 10 23:24:49 EST 1996
* Serial: 96.03.10.02
*
* This file is part of the GNU Objective C Class Library.
*
@ -20,16 +20,14 @@
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the Free
* Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*
*/
* Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
#ifndef __list_h_OBJECTS_INCLUDE
#define __list_h_OBJECTS_INCLUDE 1
/**** Included Headers *******************************************************/
#include <objects/allocs.h>
#include <Foundation/NSZone.h>
#include <objects/callbacks.h>
#include <objects/hash.h>
#include <objects/array.h>
@ -41,212 +39,308 @@ typedef struct _objects_list_node objects_list_node_t;
typedef struct _objects_list_enumerator objects_list_enumerator_t;
struct _objects_list_node
{
objects_list_t * list;
{
objects_list_t *list;
objects_list_node_t *next_in_list;
objects_list_node_t *prev_in_list;
objects_list_node_t *next_in_list;
objects_list_node_t *prev_in_list;
const void *element;
};
const void *element;
};
struct _objects_list
{
/* Container identifiers */
int magic;
size_t number;
char *name;
const void *extra;
objects_callbacks_t extra_callbacks;
objects_allocs_t allocs;
{
/* Container identifiers */
int magic_number;
size_t serial_number;
NSZone *zone;
NSString *name;
const void *extra;
objects_callbacks_t extra_callbacks;
/* Element callbacks */
objects_callbacks_t callbacks;
/* Element callbacks */
objects_callbacks_t callbacks;
/* Internal counters */
size_t node_count;
size_t element_count;
/* Internal counters */
size_t node_count;
size_t element_count;
/* Databanks */
objects_list_node_t *first_node;
objects_list_node_t *last_node;
};
/* Databanks */
objects_list_node_t *first_node;
objects_list_node_t *last_node;
};
struct _objects_list_enumerator
{
objects_list_t *list;
objects_list_node_t *node;
size_t forward;
};
{
objects_list_t *list;
objects_list_node_t *node;
size_t forward;
};
/**** Function Prototypes ****************************************************/
/** Basics **/
#include <objects/list-basics.h>
#include <objects/list-callbacks.h>
#include <objects/list-bas.h>
#include <objects/list-cbs.h>
/** Creating **/
objects_list_t * objects_list_alloc (void);
objects_list_t *
objects_list_alloc(void);
objects_list_t * objects_list_alloc_with_allocs (objects_allocs_t allocs);
objects_list_t *
objects_list_alloc_with_zone(NSZone *zone);
objects_list_t * objects_list_with_allocs (objects_allocs_t allocs);
objects_list_t *
objects_list_with_zone(NSZone *zone);
objects_list_t * objects_list_with_callbacks (objects_callbacks_t callbacks);
objects_list_t *
objects_list_with_callbacks(objects_callbacks_t callbacks);
objects_list_t * objects_list_with_allocs_with_callbacks (objects_allocs_t allocs, objects_callbacks_t callbacks);
objects_list_t *
objects_list_with_zone_with_callbacks(NSZone *zone,
objects_callbacks_t callbacks);
objects_list_t * objects_list_of_char_p (void);
objects_list_t *
objects_list_of_char_p(void);
objects_list_t * objects_list_of_void_p (void);
objects_list_t *
objects_list_of_non_owned_void_p(void);
objects_list_t * objects_list_of_owned_void_p (void);
objects_list_t *
objects_list_of_owned_void_p(void);
objects_list_t * objects_list_of_int (void);
objects_list_t *
objects_list_of_int(void);
objects_list_t * objects_list_of_int_p (void);
objects_list_t *
objects_list_of_int_p(void);
objects_list_t * objects_list_of_id (void);
objects_list_t *
objects_list_of_id(void);
/** Initializing **/
objects_list_t * objects_list_init (objects_list_t * list);
objects_list_t *
objects_list_init(objects_list_t *list);
objects_list_t * objects_list_init_with_callbacks (objects_list_t * list, objects_callbacks_t callbacks);
objects_list_t *
objects_list_init_with_callbacks(objects_list_t *list,
objects_callbacks_t callbacks);
/** Copying **/
objects_list_t * objects_list_copy (objects_list_t * old_list);
objects_list_t *
objects_list_copy(objects_list_t *old_list);
objects_list_t * objects_list_copy_with_allocs (objects_list_t * old_list, objects_allocs_t allocs);
objects_list_t *
objects_list_copy_with_zone(objects_list_t *old_list,
NSZone *zone);
/** Destroying **/
void objects_list_dealloc (objects_list_t * list);
void
objects_list_dealloc(objects_list_t *list);
/** Comparing **/
int objects_list_is_equal_to_list (objects_list_t * list, objects_list_t * other_list);
int
objects_list_is_equal_to_list(objects_list_t *list,
objects_list_t *other_list);
/** Concatenating **/
objects_list_t * objects_list_append_list (objects_list_t * base_list, objects_list_t * suffix_list);
objects_list_t *
objects_list_append_list(objects_list_t *base_list,
objects_list_t *suffix_list);
objects_list_t * objects_list_prepend_list (objects_list_t * base_list, objects_list_t * prefix_list);
objects_list_t *
objects_list_prepend_list(objects_list_t *base_list,
objects_list_t *prefix_list);
objects_list_t * objects_list_at_index_insert_list (objects_list_t * base_list, long int n, objects_list_t * infix_list);
objects_list_t *
objects_list_at_index_insert_list(objects_list_t *base_list,
long int n,
objects_list_t *infix_list);
/** Permuting **/
objects_list_t * objects_list_roll_to_nth_element (objects_list_t * list, long int n);
objects_list_t *
objects_list_roll_to_nth_element(objects_list_t *list, long int n);
objects_list_t * objects_list_roll_to_element (objects_list_t * list, const void *element);
objects_list_t *
objects_list_roll_to_element(objects_list_t *list, const void *element);
objects_list_t * objects_list_roll_to_nth_occurrance_of_element (objects_list_t * list, long int n, const void *element);
objects_list_t *
objects_list_roll_to_nth_occurrance_of_element(objects_list_t *list,
long int n,
const void *element);
objects_list_t * objects_list_invert (objects_list_t * list);
objects_list_t *
objects_list_invert(objects_list_t *list);
objects_list_t * objects_list_swap_elements_at_indices (objects_list_t * list, long int m, long int n);
objects_list_t *
objects_list_swap_elements_at_indices(objects_list_t *list,
long int m,
long int n);
/** Adding **/
const void *objects_list_append_element (objects_list_t * list, const void *element);
const void *
objects_list_append_element(objects_list_t *list, const void *element);
const void *objects_list_append_element_if_absent (objects_list_t * list, const void *element);
const void *
objects_list_append_element_if_absent(objects_list_t *list,
const void *element);
const void *objects_list_prepend_element (objects_list_t * list, const void *element);
const void *
objects_list_prepend_element(objects_list_t *list, const void *element);
const void *objects_list_prepend_element_if_absent (objects_list_t * list, const void *element);
const void *
objects_list_prepend_element_if_absent(objects_list_t *list,
const void *element);
const void *objects_list_at_index_insert_element (objects_list_t * list, long int n, const void *element);
const void *
objects_list_at_index_insert_element(objects_list_t *list,
long int n,
const void *element);
const void *objects_list_at_index_insert_element_if_absent (objects_list_t * list, long int n, const void *element);
const void *
objects_list_at_index_insert_element_if_absent(objects_list_t *list,
long int n,
const void *element);
const void *objects_list_queue_push_element (objects_list_t * list, const void *element);
const void *
objects_list_queue_push_element(objects_list_t *list, const void *element);
const void *objects_list_stack_push_element (objects_list_t * list, const void *element);
const void *
objects_list_stack_push_element(objects_list_t *list, const void *element);
/** Replacing **/
void objects_list_replace_nth_occurrance_of_element (objects_list_t * list, long int n, const void *old_element, const void *new_element);
void
objects_list_replace_nth_occurrance_of_element(objects_list_t *list,
long int n,
const void *old_element,
const void *new_element);
void objects_list_replace_element (objects_list_t * list, const void *old_element, const void *new_element);
void
objects_list_replace_element(objects_list_t *list,
const void *old_element,
const void *new_element);
void objects_list_replace_nth_element (objects_list_t * list, long int n, const void *new_element);
void
objects_list_replace_nth_element(objects_list_t *list,
long int n,
const void *new_element);
void objects_list_replace_first_element (objects_list_t * list, const void *new_element);
void
objects_list_replace_first_element(objects_list_t *list,
const void *new_element);
void objects_list_replace_last_element (objects_list_t * list, const void *new_element);
void
objects_list_replace_last_element(objects_list_t *list,
const void *new_element);
/** Removing **/
void objects_list_remove_nth_occurrence_of_element (objects_list_t * list, long int n, const void *element);
void
objects_list_remove_nth_occurrence_of_element(objects_list_t *list,
long int n,
const void *element);
void objects_list_remove_element (objects_list_t * list, const void *element);
void
objects_list_remove_element(objects_list_t *list, const void *element);
void objects_list_remove_nth_element (objects_list_t * list, long int n);
void
objects_list_remove_nth_element(objects_list_t *list, long int n);
void objects_list_remove_first_element (objects_list_t * list);
void
objects_list_remove_first_element(objects_list_t *list);
void objects_list_remove_last_element (objects_list_t * list);
void
objects_list_remove_last_element(objects_list_t *list);
void objects_list_queue_pop_element (objects_list_t * list);
void
objects_list_queue_pop_element(objects_list_t *list);
void objects_list_queue_pop_nth_element (objects_list_t * list, long int n);
void
objects_list_queue_pop_nth_element(objects_list_t *list, long int n);
void objects_list_stack_pop_element (objects_list_t * list);
void
objects_list_stack_pop_element(objects_list_t *list);
void objects_list_stack_pop_nth_element (objects_list_t * list, long int n);
void
objects_list_stack_pop_nth_element(objects_list_t *list, long int n);
/** Emptying **/
void objects_list_empty (objects_list_t * list);
void
objects_list_empty(objects_list_t *list);
/** Searching **/
int objects_list_contains_element (objects_list_t * list, const void *element);
int
objects_list_contains_element(objects_list_t *list, const void *element);
const void *objects_list_element (objects_list_t * list, const void *element);
const void *
objects_list_element(objects_list_t *list, const void *element);
const void *objects_list_nth_element (objects_list_t * list, long int n);
const void *
objects_list_nth_element(objects_list_t *list, long int n);
const void *objects_list_first_element (objects_list_t * list);
const void *
objects_list_first_element(objects_list_t *list);
const void *objects_list_last_element (objects_list_t * list);
const void *
objects_list_last_element(objects_list_t *list);
const void **objects_list_all_elements (objects_list_t * list);
const void **
objects_list_all_elements(objects_list_t *list);
/** Enumerating **/
objects_list_enumerator_t objects_list_enumerator (objects_list_t * list);
objects_list_enumerator_t
objects_list_enumerator(objects_list_t *list);
objects_list_enumerator_t objects_list_forward_enumerator (objects_list_t * list);
objects_list_enumerator_t
objects_list_forward_enumerator(objects_list_t *list);
objects_list_enumerator_t objects_list_reverse_enumerator (objects_list_t * list);
objects_list_enumerator_t
objects_list_reverse_enumerator(objects_list_t *list);
int objects_list_enumerator_next_element (objects_list_enumerator_t *enumerator, const void **element);
int
objects_list_enumerator_next_element(objects_list_enumerator_t *enumerator,
const void **element);
/** Mapping **/
/* NO WARNING: The mapping function FCN need not be one-to-one on the
* elements of LIST. In fact, FCN may do whatever it likes. */
objects_list_t * objects_list_map_elements (objects_list_t * list, const void *(*fcn) (const void *, const void *), const void *user_data);
objects_list_t *
objects_list_map_elements(objects_list_t *list,
const void *(*fcn)(const void *, void *),
void *user_data);
/** Statistics **/
int objects_list_is_empty (objects_list_t * list);
int
objects_list_is_empty(objects_list_t *list);
size_t objects_list_count (objects_list_t * list);
size_t
objects_list_count(objects_list_t *list);
size_t objects_list_capacity (objects_list_t * list);
size_t
objects_list_capacity(objects_list_t *list);
int objects_list_check (objects_list_t * list);
int
objects_list_check(objects_list_t *list);
/** Miscellaneous **/
objects_hash_t *objects_hash_init_from_list (objects_hash_t *hash, objects_list_t * list);
objects_hash_t *
objects_hash_init_from_list(objects_hash_t *hash, objects_list_t *list);
#endif /* __list_h_OBJECTS_INCLUDE */

View file

@ -1,56 +0,0 @@
/* Magic numbers for identifying Libobjects structures.
* Copyright (C) 1994, 1995, 1996 Free Software Foundation, Inc.
*
* Author: Albin L. Jones <Albin.L.Jones@Dartmouth.EDU>
* Created: Thu Mar 2 02:10:10 EST 1994
* Updated: Sat Feb 10 15:42:11 EST 1996
* Serial: 96.02.10.01
*
* This file is part of the GNU Objective C Class Library.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the Free
* Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*
*/
#ifndef __magic_h_OBJECTS_INCLUDE
#define __magic_h_OBJECTS_INCLUDE 1
/**** Included Headers *******************************************************/
/**** Type, Constant, and Macro Definitions **********************************/
/** Magic numbers **/
#define OBJECTS_MAGIC_ARRAY 0xfa138008 /* Thu Mar 2 02:28:50 EST 1994 */
#define OBJECTS_MAGIC_DATA 0xfa131971 /* Fri Nov 24 21:46:14 EST 1995 */
#define OBJECTS_MAGIC_HASH 0xfa133ee5 /* ??? ??? ?? ??:??:?? ??? 1993 */
#define OBJECTS_MAGIC_HEAP 0xfa13beef /* Tue Sep 5 17:21:34 EDT 1995 */
#define OBJECTS_MAGIC_LIST 0xfa13600d /* Tue Sep 5 17:23:50 EDT 1995 */
#define OBJECTS_MAGIC_MAP 0xfa13abba /* ??? ??? ?? ??:??:?? ??? 1993 */
/* WARNING: Don't use these. They are not guaranteed to remain in future
* editions of this file. They are here only as a cheap fix for an
* annoying little problem. */
/* FIXME: Get rid of these. See `x-basics.[ch].in'
* and `x-callbacks.[ch].in'. */
#define _OBJECTS_MAGIC_array OBJECTS_MAGIC_ARRAY
#define _OBJECTS_MAGIC_data OBJECTS_MAGIC_DATA
#define _OBJECTS_MAGIC_hash OBJECTS_MAGIC_HASH
#define _OBJECTS_MAGIC_heap OBJECTS_MAGIC_HEAP
#define _OBJECTS_MAGIC_list OBJECTS_MAGIC_LIST
#define _OBJECTS_MAGIC_map OBJECTS_MAGIC_MAP
#endif /* __magic_h_OBJECTS_INCLUDE */

View file

@ -1,10 +1,10 @@
/* A map table for use with Libobjects.
/* A map table.
* Copyright (C) 1993, 1994, 1995, 1996 Free Software Foundation, Inc.
*
* Author: Albin L. Jones <Albin.L.Jones@Dartmouth.EDU>
* Created: ??? ??? ?? ??:??:?? ??? 1993
* Updated: Sat Feb 10 13:36:59 EST 1996
* Serial: 96.02.10.01
* Updated: Thu Mar 21 00:05:43 EST 1996
* Serial: 96.03.20.04
*
* This file is part of the GNU Objective C Class Library.
*
@ -20,21 +20,20 @@
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the Free
* Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*
*/
* Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
#ifndef __map_h_OBJECTS_INCLUDE
#define __map_h_OBJECTS_INCLUDE 1
/**** Included Headers *******************************************************/
#include <objects/allocs.h>
#include <Foundation/NSZone.h>
#include <objects/callbacks.h>
#include <objects/hash.h>
/**** Type, Constant, and Macro Definitions **********************************/
/* Need these up here because of their interdependence. */
typedef struct _objects_map objects_map_t;
typedef struct _objects_map_bucket objects_map_bucket_t;
typedef struct _objects_map_node objects_map_node_t;
@ -42,40 +41,56 @@ typedef struct _objects_map_enumerator objects_map_enumerator_t;
/* Important structures... */
/* Private type for elemental holding. */
struct _objects_map_node
{
const void *key;
const void *value;
objects_map_bucket_t *bucket;
/* The map table with which the node is associated. */
objects_map_t *map;
/* The bucket in MAP in which the node sits. */
objects_map_bucket_t *bucket;
/* These hold the BUCKET linked list together. */
objects_map_node_t *next_in_bucket;
objects_map_node_t *prev_in_bucket;
/* For enumerating over the whole map table. These make
* enumerating much quicker. They also make it safer. */
objects_map_node_t *next_in_map;
objects_map_node_t *prev_in_map;
const void *key;
const void *value;
};
/* Private type for holding chains of nodes. */
struct _objects_map_bucket
{
/* The number of nodes in this bucket. For internal consistency checks. */
size_t node_count;
/* The number of elements in this bucket. (This had *better* be
* the same as NODE_COUNT, or something's wrong.) */
size_t element_count;
/* The head of this bucket's linked list of nodes. */
objects_map_node_t *first_node;
};
/* The map table type. */
struct _objects_map
{
/* Container identifiers */
int magic;
size_t number;
char *name;
/* All structures have these...
* And all structures have them in the same order. */
int magic_number;
size_t serial_number;
NSZone *zone;
NSString *name;
const void *extra;
objects_callbacks_t extra_callbacks;
objects_allocs_t allocs;
objects_callbacks_t key_callbacks;
/* Management information */
/* For keys...And Values. */
objects_callbacks_t key_callbacks;
objects_callbacks_t value_callbacks;
/* Internal counters */
@ -83,248 +98,332 @@ struct _objects_map
size_t node_count;
size_t element_count;
/* Databanks */
objects_map_bucket_t *buckets;
objects_map_node_t *first_node;
/* Places to start looking for elements. */
objects_map_bucket_t *buckets; /* Organized as a hash. */
objects_map_node_t *first_node; /* Organized as a linked list.
* (For enumerating...) */
};
/* Type for enumerating the elements of a map table. */
struct _objects_map_enumerator
{
objects_map_t *map;
objects_map_node_t *node;
objects_map_t *map; /* To which hash do I belong? */
objects_map_node_t *node; /* Which node is next? */
};
/**** Function Prototypes ****************************************************/
/** Basics **/
/** Basics... **/
#include <objects/map-basics.h>
#include <objects/map-callbacks.h>
/* All the structures (hashes, maps, lists, and arrays) have
* the same basic ideas behind them. */
/** Altering capacity **/
#include <objects/map-bas.h>
#include <objects/map-cbs.h>
size_t
objects_map_resize (objects_map_t * map, size_t new_capacity);
/** Callbacks... **/
size_t
objects_map_rightsize (objects_map_t * map);
/* Returns a collection of callbacks for use with hash tables. */
objects_callbacks_t
objects_callbacks_for_map(void);
/** Creating **/
/** Creating... **/
/* Allocate a hash table in the default zone. */
objects_map_t *
objects_map_alloc(void);
/* Allocate a hash table in the memory block ZONE. */
objects_map_t *
objects_map_alloc_with_zone(NSZone *zone);
/* Create an empty map table in the memory block ZONE. The returned
* hash table has a "reasonable" default capacity, but will need to
* be resized to suit your specific needs if more than a couple of
* dozen key/value pairs will be placed within it. */
objects_map_t *
objects_map_with_zone_with_callbacks(NSZone *zone,
objects_callbacks_t key_callbacks,
objects_callbacks_t value_callbacks);
/* Like calling 'objects_map_with_zone_with_callbacks(0, key_callbacks,
* value_callbacks)'. */
objects_map_t *
objects_map_with_callbacks(objects_callbacks_t key_callbacks,
objects_callbacks_t value_callbacks);
/* Like calling 'objects_map_with_zone_with_callbacks(0,
* objects_callbacks_standard(), objects_callbacks_standard())'. */
objects_map_t *
objects_map_with_zone(NSZone *zone);
/* Shortcuts... */
objects_map_t *objects_map_of_int(void);
objects_map_t *objects_map_of_int_to_char_p(void);
objects_map_t *objects_map_of_int_to_non_owned_void_p(void);
objects_map_t *objects_map_of_int_to_id(void);
objects_map_t *objects_map_of_char_p(void);
objects_map_t *objects_map_of_char_p_to_int(void);
objects_map_t *objects_map_of_char_p_to_non_owned_void_p(void);
objects_map_t *objects_map_of_char_p_to_id(void);
objects_map_t *objects_map_of_non_owned_void_p(void);
objects_map_t *objects_map_of_non_owned_void_p_to_int(void);
objects_map_t *objects_map_of_non_owned_void_p_to_char_p(void);
objects_map_t *objects_map_of_non_owned_void_p_to_id(void);
objects_map_t *objects_map_of_id(void);
/** Initializing... **/
objects_map_t *
objects_map_alloc (void);
objects_map_init(objects_map_t *map);
objects_map_t *
objects_map_alloc_with_allocs (objects_allocs_t allocs);
objects_map_init_with_callbacks(objects_map_t *map,
objects_callbacks_t key_callbacks,
objects_callbacks_t value_callbacks);
objects_map_t *
objects_map (void);
object_map_init_from_map(objects_map_t *map, objects_map_t *old_map);
objects_map_t *
objects_map_with_allocs (objects_allocs_t allocs);
objects_map_t *
objects_map_with_allocs_with_callbacks (objects_allocs_t allocs,
objects_callbacks_t key_callbacks,
objects_callbacks_t value_callbacks);
objects_map_t *
objects_map_with_callbacks (objects_callbacks_t key_callbacks,
objects_callbacks_t value_callbacks);
objects_map_t *
objects_map_of_int (void);
objects_map_t *
objects_map_of_int_to_char_p (void);
objects_map_t *
objects_map_of_int_to_void_p (void);
objects_map_t *
objects_map_of_int_to_float (void);
objects_map_t *
objects_map_of_char_p (void);
objects_map_t *
objects_map_of_char_p_to_int (void);
objects_map_t *
objects_map_of_char_p_to_void_p (void);
objects_map_t *
objects_map_of_char_p_to_float (void);
objects_map_t *
objects_map_of_void_p (void);
objects_map_t *
objects_map_of_void_p_to_int (void);
objects_map_t *
objects_map_of_void_p_to_char_p (void);
objects_map_t *
objects_map_of_void_p_to_float (void);
objects_map_t *
objects_map_of_float (void);
objects_map_t *
objects_map_of_double (void);
/** Initializing **/
objects_map_t *
objects_map_init (objects_map_t * map);
objects_map_t *
objects_map_init_with_callbacks (objects_map_t * map,
objects_callbacks_t key_callbacks,
objects_callbacks_t value_callbacks);
/** Destroying **/
/** Destroying... **/
/* Releases all the keys and values of MAP, and then
* deallocates MAP itself. */
void
objects_map_dealloc (objects_map_t * map);
objects_map_dealloc(objects_map_t *map);
/** Gathering statistics on a mapionary **/
/** Gathering statistics on a map... **/
/* Returns the number of key/value pairs in MAP. */
size_t
objects_map_pair_count (objects_map_t * map);
objects_map_count(objects_map_t *map);
/* Returns some (inexact) measure of how many key/value pairs
* MAP can comfortably hold without resizing. */
size_t
objects_map_capacity (objects_map_t * map);
objects_map_capacity(objects_map_t *map);
/* Performs an internal consistency check, returns 'true' if
* everything is OK, 'false' otherwise. Really useful only
* for debugging. */
int
objects_map_check_map (objects_map_t * map);
objects_map_check(objects_map_t *map);
/** Finding elements in a mapionary **/
/** Finding elements in a map... **/
/* Returns 'true' if and only if some key in MAP is equal
* (in the sense of the key callbacks of MAP) to KEY. */
int
objects_map_contains_key (objects_map_t * map, const void *key);
objects_map_contains_key(objects_map_t *map, const void *key);
/* Returns 'true' if and only if some value in MAP is equal
* (in the sense of the value callbacks of MAP) to VALUE. */
/* WARNING: This is rather inefficient. Not to be used lightly. */
int
objects_map_key_and_value (objects_map_t * map,
const void *key,
void **old_key,
void **value);
objects_map_contains_value(objects_map_t *map, const void *value);
/* If KEY is in MAP, then the following three things happen:
* (1) 'true' is returned;
* (2) if OLD_KEY is non-zero, then the key in MAP
* equal to KEY is placed there;
* (3) if VALUE is non-zero, then the value in MAP
* mapped to by KEY is placed there.
* If KEY is not in MAP, then the following three things happen:
* (1) 'false' is returned;
* (2) if OLD_KEY is non-zero, then the "not a key marker"
* for MAP is placed there;
* (3) if VALUE is non-zero, then the the "not a value marker"
* for MAP is placed there. */
int
objects_map_key_and_value_at_key(objects_map_t *map,
const void **old_key,
const void **value,
const void *key);
/* If KEY is in MAP, then the key of MAP which is equal to KEY
* is returned. Otherwise, the "not a key marker" for MAP is returned. */
const void *
objects_map_key (objects_map_t * map, const void *key);
objects_map_key_at_key(objects_map_t *map, const void *key);
/* If KEY is in MAP, then the value of MAP which to which KEY maps
* is returned. Otherwise, the "not a value marker" for MAP is returned. */
const void *
objects_map_value_at_key (objects_map_t * map, const void *key);
objects_map_value_at_key(objects_map_t *map, const void *key);
/** Enumerating the nodes and elements of a mapionary **/
/** Enumerating the nodes and elements of a map... **/
objects_map_enumerator_t
objects_map_enumerator (objects_map_t * map);
objects_map_enumerator_for_map(objects_map_t *map);
int
objects_map_enumerator_next_key_and_value (objects_map_enumerator_t *enumeratr,
const void **key,
const void **value);
objects_map_enumerator_next_key_and_value(objects_map_enumerator_t *enumerator,
const void **key,
const void **value);
int
objects_map_enumerator_next_key (objects_map_enumerator_t * enumerator,
const void **key);
objects_map_enumerator_next_key(objects_map_enumerator_t *enumerator,
const void **key);
int
objects_map_enumerator_next_value (objects_map_enumerator_t * enumerator,
const void **value);
objects_map_enumerator_next_value(objects_map_enumerator_t *enumerator,
const void **value);
/** Obtaining an array of the elements of a mapionary **/
/** Obtaining an array of the elements of a map... **/
const void **
objects_map_all_keys_and_values (objects_map_t * map);
objects_map_all_keys_and_values(objects_map_t *map);
const void **
objects_map_all_keys (objects_map_t * map);
objects_map_all_keys(objects_map_t *map);
const void **
objects_map_all_values (objects_map_t * map);
objects_map_all_values(objects_map_t *map);
/** Removing **/
/** Removing... **/
/* Removes the key/value pair (if any) from MAP whose key is KEY. */
void
objects_map_remove_key (objects_map_t * map, const void *key);
objects_map_remove_key(objects_map_t *map, const void *key);
/* Releases all of the keys and values of MAP without
* altering MAP's capacity. */
void
objects_map_empty (objects_map_t * map);
objects_map_empty(objects_map_t *map);
/** Adding **/
/** Adding... **/
const void *
objects_map_at_key_put_value_known_absent (objects_map_t * map,
const void *key,
const void *value);
objects_map_at_key_put_value_known_absent(objects_map_t *map,
const void *key,
const void *value);
const void *
objects_map_at_key_put_value (objects_map_t * map,
const void *key,
const void *value);
objects_map_at_key_put_value(objects_map_t *map,
const void *key,
const void *value);
const void *
objects_map_at_key_put_value_if_absent (objects_map_t * map,
const void *key,
const void *value);
objects_map_at_key_put_value_if_absent(objects_map_t *map,
const void *key,
const void *value);
/** Replacing **/
/** Replacing... **/
void
objects_map_replace_key (objects_map_t * map, const void *key);
objects_map_replace_key(objects_map_t *map, const void *key);
/** Comparing **/
/** Comparing... **/
/* Returns 'true' if every key/value pair of MAP2 is also a key/value pair
* of MAP1. Otherwise, returns 'false'. */
int
objects_map_contains_map (objects_map_t * map1, objects_map_t * map2);
objects_map_contains_map(objects_map_t *map1, objects_map_t *map2);
/* Returns 'true' if MAP1 and MAP2 have the same number of key/value pairs,
* MAP1 contains MAP2, and MAP2 contains MAP1. Otherwise, returns 'false'. */
int
objects_map_is_equal_to_map (objects_map_t * map1, objects_map_t * map2);
objects_map_is_equal_to_map(objects_map_t *map1, objects_map_t *map2);
/** Copying **/
/* Returns 'true' iff every key of MAP2 is a key of MAP1. */
int
objects_map_keys_contain_keys_of_map(objects_map_t *map1, objects_map_t *map2);
/* Returns 'true' if MAP1 and MAP2 have the same number of key/value pairs,
* MAP1 contains every key of MAP2, and MAP2 contains every key of MAP1.
* Otherwise, returns 'false'. */
int
objects_map_keys_are_equal_to_keys_of_map(objects_map_t *map1,
objects_map_t *map2);
/* Returns 'true' iff some key/value pair of MAP1 if also
* a key/value pair of MAP2. */
int
objects_map_intersects_map(objects_map_t *map1, objects_map_t *map2);
/* Returns 'true' iff some key of MAP1 if also a key of MAP2. */
int
objects_map_keys_intersect_keys_of_map(objects_map_t *map1,
objects_map_t *map2);
/** Copying... **/
/* Returns a copy of OLD_MAP in ZONE. Remember that, as far as what
* (if anything) OLD_MAP's keys and values point to, this copy is
* shallow. If, for example, OLD_MAP is a map from int to int, then
* you've got nothing more to worry about. If, however, OLD_MAP is a
* map from id to id, and you want the copy of OLD_MAP to be "deep",
* you'll need to use the mapping functions below to make copies of
* all of the returned map's elements. */
objects_map_t *
objects_map_copy_with_allocs (objects_map_t * old_map, objects_allocs_t new_allocs);
objects_map_copy_with_zone(objects_map_t *old_map, NSZone *zone);
/* Just like 'objects_map_copy_with_zone()', but returns a copy of
* OLD_MAP in the default zone. */
objects_map_t *
objects_map_copy (objects_map_t * old_map);
objects_map_copy(objects_map_t *old_map);
/** Mapping **/
/** Mapping... **/
/* WARNING: The mapping function KFCN must be one-to-one on the keys
* of MAP. I.e., `objects_map_map_keys()' makes no provision for the
* possibility that KFCN maps two unequal keys of MAP to the same (or
* equal) keys. */
/* Iterates through MAP, replacing each key with the result of
* '(*kfcn)(key, user_data)'. Useful for deepening copied maps
* and other uniform (and one-to-one) transformations of map keys. */
/* WARNING: The mapping function KFCN *must* be one-to-one on the
* (equivalence classes of) keys of MAP. I.e., for efficiency's sake,
* `objects_map_map_keys()' makes no provision for the possibility
* that KFCN maps two unequal keys of MAP to the same (or equal) keys. */
objects_map_t *
objects_map_map_keys (objects_map_t * map,
const void *(*kfcn) (const void *, const void *),
const void *user_data);
objects_map_map_keys(objects_map_t *map,
const void *(*kfcn)(const void *, void *),
void *user_data);
/* Iterates through MAP, replacing each value with the result of
* '(*vfcn)(value, user_data)'. Useful for deepening copied maps
* and other uniform transformations of map keys. */
/* NO WARNING: The mapping function VFCN need not be one-to-one on
* (the equivalence classes of) values. */
objects_map_t *
objects_map_map_values (objects_map_t * map,
const void *(*vfcn) (const void *, const void *),
const void *user_data);
objects_map_map_values(objects_map_t *map,
const void *(*vfcn)(const void *, void *),
void *user_data);
/** Miscellaneous **/
/** Resizing... **/
/* Resizes MAP to be ready to contain (at least) NEW_CAPACITY many elements.
* However, as far as you are concerned, it is indeterminate what exactly
* this means. After receiving and successfully processing this call,
* you are *not* guaranteed that MAP has actually set aside space for
* NEW_CAPACITY elements, for example. All that you are guaranteed is that,
* to the best of its ability, MAP will incur no loss in efficiency so long
* as it contains no more than NEW_CAPACITY elements. */
size_t
objects_map_resize(objects_map_t *map, size_t new_capacity);
/* Shrinks (or grows) MAP to be comfortable with the number of elements
* it contains. In all likelyhood, after this call, MAP is more efficient
* in terms of its speed of search vs. use of space balance. */
size_t
objects_map_rightsize(objects_map_t *map);
/** Describing... **/
/* Returns a string describing (the contents of) MAP. */
NSString *
objects_map_description(objects_map_t *map);
/** Set theoretic operations... **/
objects_map_t *
objects_map_intersect_map (objects_map_t * map, objects_map_t * other_map);
objects_map_intersect_map(objects_map_t *map, objects_map_t *other_map);
objects_map_t *
objects_map_minus_map (objects_map_t * map, objects_map_t * other_map);
objects_map_minus_map(objects_map_t *map, objects_map_t *other_map);
objects_map_t *
objects_map_union_map (objects_map_t * map, objects_map_t * other_map);
objects_map_union_map(objects_map_t *map, objects_map_t *other_map);
objects_hash_t *
objects_hash_init_from_map_keys (objects_hash_t * hash, objects_map_t * map);
objects_hash_init_from_map_keys(objects_hash_t *hash, objects_map_t *map);
objects_hash_t *
objects_hash_init_from_map_values (objects_hash_t * hash, objects_map_t * map);
objects_hash_init_from_map_values(objects_hash_t *hash, objects_map_t *map);
#endif /* __map_h_OBJECTS_INCLUDE */

View file

@ -1,51 +0,0 @@
/* GCC macros for minimum and maximum.
* Copyright (C) 1996 Free Software Foundation, Inc.
*
* Author: Albin L. Jones <Albin.L.Jones@Dartmouth.EDU>
* Created: Sat Feb 10 21:13:04 EST 1996
* Updated: Sat Feb 10 21:13:04 EST 1996
* Serial: 96.02.10.01
*
* This file is part of the GNU Objective C Class Library.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the Free
* Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*
*/
#ifndef __minmax_h_OBJECTS_INCLUDE
#define __minmax_h_OBJECTS_INCLUDE 1
/**** Included Headers *******************************************************/
/**** Type, Constant, and Macro Definitions **********************************/
#ifdef MIN
#undef MIN
#endif /* !MIN */
#define MIN(X, Y) \
({ typeof (X) __x = (X), __y = (Y); \
(__x < __y) ? __x : __y; })
#ifdef MAX
#undef MAX
#endif /* !MAX */
#define MAX(X, Y) \
({ typeof (X) __x = (X), __y = (Y); \
(__x > __y) ? __x : __y; })
#endif /* __minmax_h_OBJECTS_INCLUDE */

View file

@ -1,49 +0,0 @@
/* Structure counters and functions for getting at them.
* Copyright (C) 1995, 1996 Free Software Foundation, Inc.
*
* Author: Albin L. Jones <Albin.L.Jones@Dartmouth.EDU>
* Created: Sun Dec 3 00:28:01 EST 1995
* Updated: Sat Feb 10 15:51:02 EST 1996
* Serial: 96.02.10.01
*
* This file is part of the GNU Objective C Class Library.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the Free
* Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*
*/
#ifndef __number_h_OBJECTS_INCLUDE
#define __number_h_OBJECTS_INCLUDE 1
/**** Included Headers *******************************************************/
#include <stdlib.h>
/**** Type, Constant, and Macro Definitions **********************************/
extern size_t ___objects_number_allocated;
extern size_t ___objects_number_deallocated;
extern size_t ___objects_number_serial;
/**** Function Prototypes ****************************************************/
size_t _objects_number_allocated(void);
size_t _objects_number_deallocated(void);
size_t _objects_number_serial(void);
#endif /* __number_h_OBJECTS_INCLUDE */

View file

@ -1,111 +0,0 @@
/* Basic functions for @XX@ structures.
* Copyright (C) 1995, 1996 Free Software Foundation, Inc.
*
* Author: Albin L. Jones <Albin.L.Jones@Dartmouth.EDU>
* Created: Mon Dec 11 01:24:48 EST 1995
* Updated: Sat Feb 10 09:56:21 EST 1996
* Serial: 96.02.10.01
*
* This file is part of the GNU Objective C Class Library.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the Free
* Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*
*/
#ifndef __@XX@_xx_h_OBJECTS_INCLUDE
#define __@XX@_xx_h_OBJECTS_INCLUDE 1
/**** Included Headers *******************************************************/
#include <stdlib.h>
#include <objects/allocs.h>
#include <objects/number.h>
#include <objects/magic.h>
/**** Type, Constant, and Macro Definitions **********************************/
#define __@XX@__ 1
/**** Function Implementations ***********************************************/
/** Magic **/
/* Returns XX's magic number. */
int objects_@XX@_magic (objects_@XX@_t *xx);
/** Allocs **/
/* Returns the allocs used to create and maintain XX. */
objects_allocs_t objects_@XX@_allocs (objects_@XX@_t *xx);
/** Names **/
/* Returns the name that was given to XX. */
const char *objects_@XX@_name (objects_@XX@_t *xx);
/* Gives XX a name. Space is allocated, and the contents of the
* NUL-terminated NAME are copied. Deallocating XX frees up the
* space. I.e., it is not the responsibility of the programmer to
* keep track of space allocated for this procedure. */
const char *objects_@XX@_set_name (objects_@XX@_t *xx, const char *name);
/* Takes away XX's name. */
void objects_@XX@_unset_name (objects_@XX@_t *xx);
/** Number **/
/* Returns the (process-wide) unique number given to the Libfn
* structure XX. See <objects/number.h> for more info. */
size_t objects_@XX@_serial_number (objects_@XX@_t *xx);
/* Gives XX a new (process-wide) unique number. Numbers are not
* reused. See <objects/number.h> for more info. */
size_t _objects_@XX@_set_serial_number (objects_@XX@_t *xx);
/** Extras **/
/* Sets the callbacks associated with XX's ``extra''. NOTE: This must
* be done before calling `objects_@XX@_set_extra()', as these callbacks
* are used in that routine. */
objects_callbacks_t objects_@XX@_set_extra_callbacks (objects_@XX@_t *xx, objects_callbacks_t callbacks);
/* Returns the callbacks associated with XX's ``extra''. */
objects_callbacks_t objects_@XX@_extra_callbacks (objects_@XX@_t *xx, objects_callbacks_t callbacks);
/* Returns XX's ``extra'', a little extra space that each Libobjects
* structure carries around with it. Its use is
* implementation-dependent. */
const void *objects_@XX@_extra (objects_@XX@_t *xx);
/* Sets XX's ``extra'', a little extra space that each Libobjets structure
* carries around with it. Its use is implementation-dependent. */
const void *objects_@XX@_set_extra (objects_@XX@_t *xx, const void *extra);
/* Resets XX's ``extra''. */
void objects_@XX@_unset_extra (objects_@XX@_t *xx);
/** Low-level Creation and Destruction **/
/* Handles the universal, low-level allocation of Libobjects structures. */
objects_@XX@_t *_objects_@XX@_alloc_with_allocs (objects_allocs_t allocs);
/* Handles the universal, low-level deallocation of Libobjects structures. */
void _objects_@XX@_dealloc (objects_@XX@_t *xx);
/* Handles the low-level copying of Libobjects structures. */
objects_@XX@_t *_objects_@XX@_copy_with_allocs (objects_@XX@_t *xx, objects_allocs_t allocs);
#endif /* __@XX@_xx_h_OBJECTS_INCLUDE */

View file

@ -1,71 +0,0 @@
/* Getting callbacks from @YY@ structures.
* Copyright (C) 1995, 1996 Free Software Foundation, Inc.
*
* Author: Albin L. Jones <Albin.L.Jones@Dartmouth.EDU>
* Created: Mon Dec 11 03:41:00 EST 1995
* Updated: Sat Feb 10 10:21:13 EST 1996
* Serial: 96.02.10.01
*
* This file is part of the GNU Objective C Class Library.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the Free
* Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*
*/
#ifndef __@YY@_yy_h_OBJECTS_INCLUDE
#define __@YY@_yy_h_OBJECTS_INCLUDE 1
/**** Included Headers *******************************************************/
#include <objects/callbacks.h>
#include <objects/@YY@.h>
/**** Type, Constant, and Macro Definitions **********************************/
#define __@YY@__ 1
/**** Function Implementations ***********************************************/
#ifdef __map__
/** Callbacks **/
/* Returns the callbacks associated with YY's keys. */
objects_callbacks_t objects_@YY@_key_callbacks (objects_@YY@_t *yy);
/* Returns the ``bogus'' marker associated with YY's keys. */
const void *objects_@YY@_not_a_key_marker (objects_@YY@_t *yy);
/* Returns the callbacks associated with YY's values. */
objects_callbacks_t
objects_@YY@_value_callbacks (objects_@YY@_t *yy);
/* Returns the ``bogus'' marker associated with YY's values. */
const void *objects_@YY@_not_a_value_marker (objects_@YY@_t *yy);
#else /* !__map__ */
/** Callbacks **/
/* Returns the callbacks associated with YY's elements. */
objects_callbacks_t objects_@YY@_element_callbacks (objects_@YY@_t *yy);
/* Returns the ``bogus'' marker associated with YY's elements. */
const void *objects_@YY@_not_an_element_marker (objects_@YY@_t *yy);
#endif /* __map__ */
#endif /* __@YY@_yy_h_OBJECTS_INCLUDE */

View file

@ -1,276 +0,0 @@
/* Basic functions for @XX@ structures.
* Copyright (C) 1995, 1996 Free Software Foundation, Inc.
*
* Author: Albin L. Jones <Albin.L.Jones@Dartmouth.EDU>
* Created: Tue Dec 12 12:33:01 EST 1995
* Updated: Sat Feb 10 09:08:35 EST 1996
* Serial: 96.02.10.01
*
* This file is part of the GNU Objective C Class Library.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the Free
* Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*
*/
/**** Included Headers *******************************************************/
#include <objects/allocs.h>
#include <objects/number.h>
#include <objects/magic.h>
#include <objects/@XX@.h>
/**** Type, Constant, and Macro Definitions **********************************/
#define __@XX@__ 1
/**** Function Implementations ***********************************************/
/** Magic **/
/* Returns XX's magic number. */
int
objects_@XX@_magic (objects_@XX@_t *xx)
{
return xx->magic;
}
/** Allocs **/
/* Returns the allocs used to create and maintain XX. */
objects_allocs_t
objects_@XX@_allocs (objects_@XX@_t *xx)
{
return xx->allocs;
}
/** Names **/
/* Returns the name that was given to XX. */
const char *
objects_@XX@_name (objects_@XX@_t *xx)
{
return xx->name;
}
/* Gives XX a name. Space is allocated, and the contents of the
* NUL-terminated NAME are copied. Deallocating XX frees up the
* space. I.e., it is not the responsibility of the programmer to
* keep track of space allocated for this procedure. */
const char *
objects_@XX@_set_name (objects_@XX@_t *xx, const char *name)
{
/* Figure out how much space we need. */
size_t len = strlen (name);
const char *old_name = xx->name;
/* Allocate space for the new name. (Don't forget the extra space
* for the terminating `NUL'. */
xx->name = (char *) objects_malloc (xx->allocs, len + 1);
/* If the allocation was successful, copy the new name over and get
* rid of the old name. */
if (xx->name != NULL)
{
/* Copy over the new name. */
strncpy (xx->name, name, len);
/* Free up any space we set aside for any older name. */
if (old_name != NULL)
objects_free (xx->allocs, old_name);
}
return xx->name;
}
/* Takes away XX's name. */
void
objects_@XX@_unset_name (objects_@XX@_t *xx)
{
/* Free it. */
if (xx->name != NULL)
objects_free (xx->allocs, xx->name);
/* Reset it. */
xx->name = NULL;
return;
}
/** Number **/
/* Returns the (process-wide) unique number given to the Libobjects
* structure XX. See <objects/number.h> for more info. */
size_t
objects_@XX@_number (objects_@XX@_t *xx)
{
return xx->number;
}
/* Gives XX a new (process-wide) unique number. Numbers are not
* reused. See <objects/number.h> for more info. */
size_t
_objects_@XX@_set_serial_number (objects_@XX@_t *xx)
{
size_t old_number;
old_number = xx->number;
xx->number = (___objects_number_serial)++;
return old_number;
}
/** Extras **/
/* Sets the callbacks associated with XX's ``extra''. NOTE: This must
* be done before calling `objects_@XX@_set_extra()', as these callbacks
* are used in that routine. */
objects_callbacks_t
objects_@XX@_set_extra_callbacks (objects_@XX@_t *xx, objects_callbacks_t callbacks)
{
objects_callbacks_t old_callbacks;
/* Remember the old callbacks for later. */
old_callbacks = xx->extra_callbacks;
/* Set the new callbacks. */
xx->extra_callbacks = callbacks;
/* Release the old contents. */
objects_release (old_callbacks, (void*)xx->extra, xx);
/* Set the contents to something noticible. */
xx->extra = (xx->extra_callbacks).not_an_item_marker;
return old_callbacks;
}
/* Returns the callbacks associated with XX's ``extra''. */
objects_callbacks_t
objects_@XX@_extra_callbacks (objects_@XX@_t *xx, objects_callbacks_t callbacks)
{
return xx->extra_callbacks;
}
/* Returns XX's ``extra'', a little extra space that each Libobjects
* structure carries around with it. Its use is
* implementation-dependent. */
const void *
objects_@XX@_extra (objects_@XX@_t *xx)
{
return xx->extra;
}
/* Sets XX's ``extra'', a little extra space that each Libobjects structure
* carries around with it. Its use is implementation-dependent. */
const void *
objects_@XX@_set_extra (objects_@XX@_t *xx, const void *extra)
{
const void *old_extra;
/* Out with the old, and in with the new. */
old_extra = xx->extra;
xx->extra = objects_retain (xx->extra_callbacks, extra, xx);
objects_release (xx->extra_callbacks, (void*)old_extra, xx);
return old_extra;
}
/* Resets XX's ``extra''. */
void
objects_@XX@_unset_extra (objects_@XX@_t *xx)
{
/* Release XX's extra. */
objects_release (xx->extra_callbacks, (void*)xx->extra, xx);
/* Reset XX's extra. */
xx->extra = (xx->extra_callbacks).not_an_item_marker;
return;
}
/** Low-level Creation and Destruction **/
/* Handles the universal, low-level allocation of Libobjects structures. */
objects_@XX@_t *
_objects_@XX@_alloc_with_allocs (objects_allocs_t allocs)
{
objects_@XX@_t *xx;
/* Try to allocate some space for XX. */
xx = objects_malloc (allocs, sizeof (objects_@XX@_t));
/* The `objects_malloc()' was successful. */
if (xx != NULL)
{
_objects_@XX@_set_serial_number (xx);
xx->magic = _OBJECTS_MAGIC_@XX@;
xx->name = NULL;
xx->allocs = allocs;
xx->extra_callbacks = objects_callbacks_for_void_p;
xx->extra = 0;
/* Increment the counter of allocated Libobjects structures. */
++(___objects_number_allocated);
}
return xx;
}
/* Handles the universal, low-level deallocation of Libobjects structures. */
void
_objects_@XX@_dealloc (objects_@XX@_t *xx)
{
/* Make sure XX is valid. */
if (xx != NULL)
{
/* Free up any space we needed to keep track of XX's name. */
if (xx->name != NULL)
objects_free (objects_@XX@_allocs (xx), xx->name);
/* Release XX's extra. */
objects_@XX@_unset_extra (xx);
/* Free up XX itself. */
objects_free (objects_@XX@_allocs (xx), xx);
/* Increment the counter of deallocated Libobjects structures. */
++(___objects_number_deallocated);
}
return;
}
/* Handles the low-level copying of Libobjects structures. */
objects_@XX@_t *
_objects_@XX@_copy_with_allocs (objects_@XX@_t *xx, objects_allocs_t allocs)
{
objects_@XX@_t *new;
/* Create a new structure. */
new = _objects_@XX@_alloc_with_allocs (allocs);
if (new != NULL)
{
/* Copy over XX's name. */
objects_@XX@_set_name (new, objects_@XX@_name (xx));
/* Copy over XX's extras. */
objects_@XX@_set_extra_callbacks (new, xx->extra_callbacks);
objects_@XX@_set_extra (new, xx->extra);
}
return new;
}

View file

@ -1,89 +0,0 @@
/* Getting callbacks from @YY@ structures.
* Copyright (C) 1995, 1996 Free Software Foundation, Inc.
*
* Author: Albin L. Jones <Albin.L.Jones@Dartmouth.EDU>
* Created: Mon Dec 11 02:44:09 EST 1995
* Updated: Sat Feb 10 10:08:59 EST 1996
* Serial: 96.02.10.01
*
* This file is part of the GNU Objective C Class Library.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the Free
* Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*
*/
/**** Included Headers *******************************************************/
#include <objects/callbacks.h>
#include <objects/@YY@.h>
/**** Type, Constant, and Macro Definitions **********************************/
#define __@YY@__ 1
/**** Function Implementations ***********************************************/
#ifdef __map__
/** Callbacks **/
/* Returns the callbacks associated with YY's keys. */
objects_callbacks_t
objects_@YY@_key_callbacks (objects_@YY@_t * yy)
{
return yy->key_callbacks;
}
/* Returns the ``bogus'' marker associated with YY's keys. */
const void *
objects_@YY@_not_a_key_marker (objects_@YY@_t *yy)
{
return (yy->key_callbacks).not_an_item_marker;
}
/* Returns the callbacks associated with YY's values. */
objects_callbacks_t
objects_@YY@_value_callbacks (objects_@YY@_t *yy)
{
return yy->value_callbacks;
}
/* Returns the ``bogus'' marker associated with YY's values. */
const void *
objects_@YY@_not_a_value_marker (objects_@YY@_t *yy)
{
return (yy->value_callbacks).not_an_item_marker;
}
#else /* !__map__ */
/** Callbacks **/
/* Returns the callbacks associated with YY's elements. */
objects_callbacks_t
objects_@YY@_element_callbacks (objects_@YY@_t *yy)
{
return yy->callbacks;
}
/* Returns the ``bogus'' marker associated with YY's elements. */
const void *
objects_@YY@_not_an_element_marker (objects_@YY@_t *yy)
{
return (yy->callbacks).not_an_item_marker;
}
#endif /* __map__ */