1996-02-13 02:35:45 +00:00
|
|
|
/* A map table for use with Libobjects.
|
|
|
|
* 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
|
|
|
|
*
|
|
|
|
* 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 __map_h_OBJECTS_INCLUDE
|
|
|
|
#define __map_h_OBJECTS_INCLUDE 1
|
|
|
|
|
|
|
|
/**** Included Headers *******************************************************/
|
|
|
|
|
|
|
|
#include <objects/allocs.h>
|
|
|
|
#include <objects/callbacks.h>
|
|
|
|
#include <objects/hash.h>
|
|
|
|
|
|
|
|
/**** Type, Constant, and Macro Definitions **********************************/
|
|
|
|
|
|
|
|
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;
|
|
|
|
typedef struct _objects_map_enumerator objects_map_enumerator_t;
|
|
|
|
|
|
|
|
/* Important structures... */
|
|
|
|
|
|
|
|
struct _objects_map_node
|
1996-02-22 15:25:44 +00:00
|
|
|
{
|
|
|
|
const void *key;
|
|
|
|
const void *value;
|
1996-02-13 02:35:45 +00:00
|
|
|
|
1996-02-22 15:25:44 +00:00
|
|
|
objects_map_bucket_t *bucket;
|
|
|
|
objects_map_t *map;
|
1996-02-13 02:35:45 +00:00
|
|
|
|
1996-02-22 15:25:44 +00:00
|
|
|
objects_map_node_t *next_in_bucket;
|
|
|
|
objects_map_node_t *prev_in_bucket;
|
|
|
|
objects_map_node_t *next_in_map;
|
|
|
|
objects_map_node_t *prev_in_map;
|
|
|
|
};
|
1996-02-13 02:35:45 +00:00
|
|
|
|
|
|
|
struct _objects_map_bucket
|
1996-02-22 15:25:44 +00:00
|
|
|
{
|
|
|
|
size_t node_count;
|
|
|
|
size_t element_count;
|
1996-02-13 02:35:45 +00:00
|
|
|
|
1996-02-22 15:25:44 +00:00
|
|
|
objects_map_node_t *first_node;
|
|
|
|
};
|
1996-02-13 02:35:45 +00:00
|
|
|
|
|
|
|
struct _objects_map
|
1996-02-22 15:25:44 +00:00
|
|
|
{
|
|
|
|
/* Container identifiers */
|
|
|
|
int magic;
|
|
|
|
size_t number;
|
|
|
|
char *name;
|
|
|
|
const void *extra;
|
|
|
|
objects_callbacks_t extra_callbacks;
|
|
|
|
objects_allocs_t allocs;
|
|
|
|
objects_callbacks_t key_callbacks;
|
1996-02-13 02:35:45 +00:00
|
|
|
|
|
|
|
/* Management information */
|
1996-02-22 15:25:44 +00:00
|
|
|
objects_callbacks_t value_callbacks;
|
1996-02-13 02:35:45 +00:00
|
|
|
|
1996-02-22 15:25:44 +00:00
|
|
|
/* Internal counters */
|
|
|
|
size_t bucket_count;
|
|
|
|
size_t node_count;
|
|
|
|
size_t element_count;
|
1996-02-13 02:35:45 +00:00
|
|
|
|
1996-02-22 15:25:44 +00:00
|
|
|
/* Databanks */
|
|
|
|
objects_map_bucket_t *buckets;
|
|
|
|
objects_map_node_t *first_node;
|
|
|
|
};
|
1996-02-13 02:35:45 +00:00
|
|
|
|
|
|
|
struct _objects_map_enumerator
|
1996-02-22 15:25:44 +00:00
|
|
|
{
|
|
|
|
objects_map_t *map;
|
|
|
|
objects_map_node_t *node;
|
|
|
|
};
|
1996-02-13 02:35:45 +00:00
|
|
|
|
|
|
|
/**** Function Prototypes ****************************************************/
|
|
|
|
|
|
|
|
/** Basics **/
|
|
|
|
|
|
|
|
#include <objects/map-basics.h>
|
|
|
|
#include <objects/map-callbacks.h>
|
|
|
|
|
|
|
|
/** Altering capacity **/
|
|
|
|
|
|
|
|
size_t
|
|
|
|
objects_map_resize (objects_map_t * map, size_t new_capacity);
|
|
|
|
|
|
|
|
size_t
|
|
|
|
objects_map_rightsize (objects_map_t * map);
|
|
|
|
|
|
|
|
/** Creating **/
|
|
|
|
|
|
|
|
objects_map_t *
|
1996-02-22 15:25:44 +00:00
|
|
|
objects_map_alloc (void);
|
1996-02-13 02:35:45 +00:00
|
|
|
|
|
|
|
objects_map_t *
|
1996-02-22 15:25:44 +00:00
|
|
|
objects_map_alloc_with_allocs (objects_allocs_t allocs);
|
1996-02-13 02:35:45 +00:00
|
|
|
|
|
|
|
objects_map_t *
|
1996-02-22 15:25:44 +00:00
|
|
|
objects_map (void);
|
1996-02-13 02:35:45 +00:00
|
|
|
|
|
|
|
objects_map_t *
|
1996-02-22 15:25:44 +00:00
|
|
|
objects_map_with_allocs (objects_allocs_t allocs);
|
1996-02-13 02:35:45 +00:00
|
|
|
|
|
|
|
objects_map_t *
|
1996-02-22 15:25:44 +00:00
|
|
|
objects_map_with_allocs_with_callbacks (objects_allocs_t allocs,
|
|
|
|
objects_callbacks_t key_callbacks,
|
|
|
|
objects_callbacks_t value_callbacks);
|
1996-02-13 02:35:45 +00:00
|
|
|
|
|
|
|
objects_map_t *
|
1996-02-22 15:25:44 +00:00
|
|
|
objects_map_with_callbacks (objects_callbacks_t key_callbacks,
|
|
|
|
objects_callbacks_t value_callbacks);
|
1996-02-13 02:35:45 +00:00
|
|
|
|
|
|
|
objects_map_t *
|
1996-02-22 15:25:44 +00:00
|
|
|
objects_map_of_int (void);
|
1996-02-13 02:35:45 +00:00
|
|
|
|
|
|
|
objects_map_t *
|
1996-02-22 15:25:44 +00:00
|
|
|
objects_map_of_int_to_char_p (void);
|
1996-02-13 02:35:45 +00:00
|
|
|
|
|
|
|
objects_map_t *
|
1996-02-22 15:25:44 +00:00
|
|
|
objects_map_of_int_to_void_p (void);
|
1996-02-13 02:35:45 +00:00
|
|
|
|
|
|
|
objects_map_t *
|
1996-02-22 15:25:44 +00:00
|
|
|
objects_map_of_int_to_float (void);
|
1996-02-13 02:35:45 +00:00
|
|
|
|
|
|
|
objects_map_t *
|
1996-02-22 15:25:44 +00:00
|
|
|
objects_map_of_char_p (void);
|
1996-02-13 02:35:45 +00:00
|
|
|
|
|
|
|
objects_map_t *
|
1996-02-22 15:25:44 +00:00
|
|
|
objects_map_of_char_p_to_int (void);
|
1996-02-13 02:35:45 +00:00
|
|
|
|
|
|
|
objects_map_t *
|
1996-02-22 15:25:44 +00:00
|
|
|
objects_map_of_char_p_to_void_p (void);
|
1996-02-13 02:35:45 +00:00
|
|
|
|
|
|
|
objects_map_t *
|
1996-02-22 15:25:44 +00:00
|
|
|
objects_map_of_char_p_to_float (void);
|
1996-02-13 02:35:45 +00:00
|
|
|
|
|
|
|
objects_map_t *
|
1996-02-22 15:25:44 +00:00
|
|
|
objects_map_of_void_p (void);
|
1996-02-13 02:35:45 +00:00
|
|
|
|
|
|
|
objects_map_t *
|
1996-02-22 15:25:44 +00:00
|
|
|
objects_map_of_void_p_to_int (void);
|
1996-02-13 02:35:45 +00:00
|
|
|
|
|
|
|
objects_map_t *
|
1996-02-22 15:25:44 +00:00
|
|
|
objects_map_of_void_p_to_char_p (void);
|
1996-02-13 02:35:45 +00:00
|
|
|
|
|
|
|
objects_map_t *
|
1996-02-22 15:25:44 +00:00
|
|
|
objects_map_of_void_p_to_float (void);
|
1996-02-13 02:35:45 +00:00
|
|
|
|
|
|
|
objects_map_t *
|
1996-02-22 15:25:44 +00:00
|
|
|
objects_map_of_float (void);
|
1996-02-13 02:35:45 +00:00
|
|
|
|
|
|
|
objects_map_t *
|
1996-02-22 15:25:44 +00:00
|
|
|
objects_map_of_double (void);
|
1996-02-13 02:35:45 +00:00
|
|
|
|
|
|
|
/** Initializing **/
|
|
|
|
|
|
|
|
objects_map_t *
|
1996-02-22 15:25:44 +00:00
|
|
|
objects_map_init (objects_map_t * map);
|
1996-02-13 02:35:45 +00:00
|
|
|
|
|
|
|
objects_map_t *
|
1996-02-22 15:25:44 +00:00
|
|
|
objects_map_init_with_callbacks (objects_map_t * map,
|
|
|
|
objects_callbacks_t key_callbacks,
|
|
|
|
objects_callbacks_t value_callbacks);
|
1996-02-13 02:35:45 +00:00
|
|
|
|
|
|
|
/** Destroying **/
|
|
|
|
|
|
|
|
void
|
1996-02-22 15:25:44 +00:00
|
|
|
objects_map_dealloc (objects_map_t * map);
|
1996-02-13 02:35:45 +00:00
|
|
|
|
|
|
|
/** Gathering statistics on a mapionary **/
|
|
|
|
|
|
|
|
size_t
|
|
|
|
objects_map_pair_count (objects_map_t * map);
|
|
|
|
|
|
|
|
size_t
|
|
|
|
objects_map_capacity (objects_map_t * map);
|
|
|
|
|
|
|
|
int
|
1996-02-22 15:25:44 +00:00
|
|
|
objects_map_check_map (objects_map_t * map);
|
1996-02-13 02:35:45 +00:00
|
|
|
|
|
|
|
/** Finding elements in a mapionary **/
|
|
|
|
|
|
|
|
int
|
1996-02-22 15:25:44 +00:00
|
|
|
objects_map_contains_key (objects_map_t * map, const void *key);
|
1996-02-13 02:35:45 +00:00
|
|
|
|
|
|
|
int
|
1996-02-22 15:25:44 +00:00
|
|
|
objects_map_key_and_value (objects_map_t * map,
|
|
|
|
const void *key,
|
|
|
|
void **old_key,
|
|
|
|
void **value);
|
1996-02-13 02:35:45 +00:00
|
|
|
|
1996-02-22 15:25:44 +00:00
|
|
|
const void *
|
|
|
|
objects_map_key (objects_map_t * map, const void *key);
|
1996-02-13 02:35:45 +00:00
|
|
|
|
1996-02-22 15:25:44 +00:00
|
|
|
const void *
|
|
|
|
objects_map_value_at_key (objects_map_t * map, const void *key);
|
1996-02-13 02:35:45 +00:00
|
|
|
|
|
|
|
/** Enumerating the nodes and elements of a mapionary **/
|
|
|
|
|
|
|
|
objects_map_enumerator_t
|
|
|
|
objects_map_enumerator (objects_map_t * map);
|
|
|
|
|
|
|
|
int
|
1996-02-22 15:25:44 +00:00
|
|
|
objects_map_enumerator_next_key_and_value (objects_map_enumerator_t *enumeratr,
|
|
|
|
const void **key,
|
|
|
|
const void **value);
|
1996-02-13 02:35:45 +00:00
|
|
|
|
|
|
|
int
|
1996-02-22 15:25:44 +00:00
|
|
|
objects_map_enumerator_next_key (objects_map_enumerator_t * enumerator,
|
|
|
|
const void **key);
|
1996-02-13 02:35:45 +00:00
|
|
|
|
|
|
|
int
|
1996-02-22 15:25:44 +00:00
|
|
|
objects_map_enumerator_next_value (objects_map_enumerator_t * enumerator,
|
|
|
|
const void **value);
|
1996-02-13 02:35:45 +00:00
|
|
|
|
|
|
|
/** Obtaining an array of the elements of a mapionary **/
|
|
|
|
|
1996-02-22 15:25:44 +00:00
|
|
|
const void **
|
|
|
|
objects_map_all_keys_and_values (objects_map_t * map);
|
1996-02-13 02:35:45 +00:00
|
|
|
|
1996-02-22 15:25:44 +00:00
|
|
|
const void **
|
|
|
|
objects_map_all_keys (objects_map_t * map);
|
1996-02-13 02:35:45 +00:00
|
|
|
|
1996-02-22 15:25:44 +00:00
|
|
|
const void **
|
|
|
|
objects_map_all_values (objects_map_t * map);
|
1996-02-13 02:35:45 +00:00
|
|
|
|
|
|
|
/** Removing **/
|
|
|
|
|
|
|
|
void
|
1996-02-22 15:25:44 +00:00
|
|
|
objects_map_remove_key (objects_map_t * map, const void *key);
|
1996-02-13 02:35:45 +00:00
|
|
|
|
|
|
|
void
|
1996-02-22 15:25:44 +00:00
|
|
|
objects_map_empty (objects_map_t * map);
|
1996-02-13 02:35:45 +00:00
|
|
|
|
|
|
|
/** Adding **/
|
|
|
|
|
1996-02-22 15:25:44 +00:00
|
|
|
const void *
|
|
|
|
objects_map_at_key_put_value_known_absent (objects_map_t * map,
|
|
|
|
const void *key,
|
|
|
|
const void *value);
|
1996-02-13 02:35:45 +00:00
|
|
|
|
1996-02-22 15:25:44 +00:00
|
|
|
const void *
|
|
|
|
objects_map_at_key_put_value (objects_map_t * map,
|
|
|
|
const void *key,
|
|
|
|
const void *value);
|
1996-02-13 02:35:45 +00:00
|
|
|
|
1996-02-22 15:25:44 +00:00
|
|
|
const void *
|
|
|
|
objects_map_at_key_put_value_if_absent (objects_map_t * map,
|
|
|
|
const void *key,
|
|
|
|
const void *value);
|
1996-02-13 02:35:45 +00:00
|
|
|
|
|
|
|
/** Replacing **/
|
|
|
|
|
|
|
|
void
|
1996-02-22 15:25:44 +00:00
|
|
|
objects_map_replace_key (objects_map_t * map, const void *key);
|
1996-02-13 02:35:45 +00:00
|
|
|
|
|
|
|
/** Comparing **/
|
|
|
|
|
|
|
|
int
|
1996-02-22 15:25:44 +00:00
|
|
|
objects_map_contains_map (objects_map_t * map1, objects_map_t * map2);
|
1996-02-13 02:35:45 +00:00
|
|
|
|
|
|
|
int
|
1996-02-22 15:25:44 +00:00
|
|
|
objects_map_is_equal_to_map (objects_map_t * map1, objects_map_t * map2);
|
1996-02-13 02:35:45 +00:00
|
|
|
|
|
|
|
/** Copying **/
|
|
|
|
|
|
|
|
objects_map_t *
|
1996-02-22 15:25:44 +00:00
|
|
|
objects_map_copy_with_allocs (objects_map_t * old_map, objects_allocs_t new_allocs);
|
1996-02-13 02:35:45 +00:00
|
|
|
|
|
|
|
objects_map_t *
|
1996-02-22 15:25:44 +00:00
|
|
|
objects_map_copy (objects_map_t * old_map);
|
1996-02-13 02:35:45 +00:00
|
|
|
|
|
|
|
/** 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. */
|
|
|
|
objects_map_t *
|
1996-02-22 15:25:44 +00:00
|
|
|
objects_map_map_keys (objects_map_t * map,
|
|
|
|
const void *(*kfcn) (const void *, const void *),
|
|
|
|
const void *user_data);
|
1996-02-13 02:35:45 +00:00
|
|
|
|
|
|
|
/* NO WARNING: The mapping function VFCN need not be one-to-one on
|
|
|
|
* (the equivalence classes of) values. */
|
|
|
|
objects_map_t *
|
1996-02-22 15:25:44 +00:00
|
|
|
objects_map_map_values (objects_map_t * map,
|
|
|
|
const void *(*vfcn) (const void *, const void *),
|
|
|
|
const void *user_data);
|
1996-02-13 02:35:45 +00:00
|
|
|
|
|
|
|
/** Miscellaneous **/
|
|
|
|
|
|
|
|
objects_map_t *
|
1996-02-22 15:25:44 +00:00
|
|
|
objects_map_intersect_map (objects_map_t * map, objects_map_t * other_map);
|
1996-02-13 02:35:45 +00:00
|
|
|
|
|
|
|
objects_map_t *
|
1996-02-22 15:25:44 +00:00
|
|
|
objects_map_minus_map (objects_map_t * map, objects_map_t * other_map);
|
1996-02-13 02:35:45 +00:00
|
|
|
|
|
|
|
objects_map_t *
|
1996-02-22 15:25:44 +00:00
|
|
|
objects_map_union_map (objects_map_t * map, objects_map_t * other_map);
|
1996-02-13 02:35:45 +00:00
|
|
|
|
|
|
|
objects_hash_t *
|
1996-02-22 15:25:44 +00:00
|
|
|
objects_hash_init_from_map_keys (objects_hash_t * hash, objects_map_t * map);
|
1996-02-13 02:35:45 +00:00
|
|
|
|
|
|
|
objects_hash_t *
|
1996-02-22 15:25:44 +00:00
|
|
|
objects_hash_init_from_map_values (objects_hash_t * hash, objects_map_t * map);
|
1996-02-13 02:35:45 +00:00
|
|
|
|
|
|
|
#endif /* __map_h_OBJECTS_INCLUDE */
|