coan 4.2.4
#include "ptr_set.h"
#include "memory.h"
#include "swiss_army.h"
#include <string.h>
#include <assert.h>
#include <stddef.h>
Include dependency graph for ptr_set.c:

Go to the source code of this file.

Data Structures

struct  ptr_set

Defines

#define SOMEWHERE(loc)   ((loc) >= 0)
#define NOWHERE(loc)   ((loc) < 0)
#define POINTER(loc)   (NOWHERE(loc) ? ~(loc) : (loc))

Functions

static int default_comparator (void const *obj, void const *key, locator_t ignore)
static void ptr_set_init (ptr_set_h ps, comparator_t compare, dtor_t dtor, cloner_t cloner)
static void ptr_set_copy_init (ptr_set_h dest, ptr_set_const_h src)
ptr_set_h ptr_set_new (comparator_t compare, dtor_t dtor, cloner_t cloner)
void ptr_set_dispose (ptr_set_h ps)
ptr_set_h ptr_set_copy (ptr_set_const_h src)
void ptr_set_swap (ptr_set_h lhs, ptr_set_h rhs)
void ptr_set_assign (ptr_set_h dest, ptr_set_const_h src)
bool ptr_set_equal (ptr_set_const_h lhs, ptr_set_const_h rhs)
comparator_t ptr_set_comparator (ptr_set_const_h ps)
dtor_t ptr_set_dtor (ptr_set_const_h ps)
cloner_t ptr_set_cloner (ptr_set_const_h ps)
size_t ptr_set_count (ptr_set_const_h ps)
void * ptr_set_search (ptr_set_h ps, char const *key, locator_t keylen)
void const * ptr_set_search_const (ptr_set_const_h ps, char const *key, locator_t keylen)
bool ptr_set_insert (ptr_set_h ps, void const *obj)
bool ptr_set_delete (ptr_set_h ps, locator_t pos)
void ** ptr_set_begin (ptr_set_const_h ps)
void ** ptr_set_end (ptr_set_const_h ps)
void const ** ptr_set_begin_const (ptr_set_const_h ps)
void const ** ptr_set_end_const (ptr_set_const_h ps)

Detailed Description

This file implements the Pointer-Set component

Definition in file ptr_set.c.


Function Documentation

void ptr_set_assign ( ptr_set_h  dest,
ptr_set_const_h  src 
)

Assign one pointer set to another.

Parameters:
destThe pointer set to be assigned
srcThe pointer set to be assigned to dest.

Definition at line 165 of file ptr_set.c.

References ptr_set_copy(), ptr_set_dispose(), and ptr_set_swap().

Referenced by configured_symbols_rewind().

Here is the call graph for this function:

void** ptr_set_begin ( ptr_set_const_h  ps)

Get a pointer to the first pointer in a pointer set. Returns NULL if the pointer set is empty.

Definition at line 290 of file ptr_set.c.

References ptr_vector_begin().

Referenced by ptr_set_begin_const().

Here is the call graph for this function:

void const** ptr_set_begin_const ( ptr_set_const_h  ps)

Const variant of ptr_set_begin()

Definition at line 304 of file ptr_set.c.

References ptr_set_begin().

Referenced by configured_symbol_find().

Here is the call graph for this function:

cloner_t ptr_set_cloner ( ptr_set_const_h  ps)

Get the cloning function from pointer set

Definition at line 203 of file ptr_set.c.

References ptr_vector_cloner().

Here is the call graph for this function:

comparator_t ptr_set_comparator ( ptr_set_const_h  ps)

Get the comparison function a pointer set

Definition at line 190 of file ptr_set.c.

ptr_set_h ptr_set_copy ( ptr_set_const_h  src)

Construct a copy of a pointer set.

Parameters:
srcThe pointer set to copy
Returns:
A copy of src.

Definition at line 145 of file ptr_set.c.

References allocate(), and ptr_set_copy_init().

Referenced by ptr_set_assign().

Here is the call graph for this function:

size_t ptr_set_count ( ptr_set_const_h  ps)

Get the number of elements in a pointer set

Definition at line 209 of file ptr_set.c.

References ptr_vector_count().

Referenced by parse_command_args().

Here is the call graph for this function:

bool ptr_set_delete ( ptr_set_h  ps,
locator_t  pos 
)

Delete a pointer from a pointer set.

Parameters:
psThe pointer set to be modified.
locThe position in the set at which to remove an element.
Returns:
True if an element is deleted, else false.

If loc lies within ps then the element at pos is removed. Otherwise nothing is done.

Definition at line 283 of file ptr_set.c.

References ptr_vector_delete(), and ptr_set::pv.

Here is the call graph for this function:

void ptr_set_dispose ( ptr_set_h  ps)

Dispose of a pointer set.

Parameters:
psThe pointer set to be destroyed.

The set's dtor member is called on each element and then remaining memory controlled by the set is released.

The function is a no-op if ps is NULL.

Definition at line 136 of file ptr_set.c.

References ptr_vector_dispose(), and ptr_set::pv.

Referenced by ptr_set_assign().

Here is the call graph for this function:

dtor_t ptr_set_dtor ( ptr_set_const_h  ps)

Get the destructor function a pointer set

Definition at line 197 of file ptr_set.c.

References ptr_vector_dtor().

Here is the call graph for this function:

void** ptr_set_end ( ptr_set_const_h  ps)

Get the pointer to the first pointer beyond the elements in a pointer set. Returns NULL if the pointer set is empty.

Definition at line 297 of file ptr_set.c.

References ptr_vector_end().

Referenced by ptr_set_end_const().

Here is the call graph for this function:

void const** ptr_set_end_const ( ptr_set_const_h  ps)

Const variant of ptr_set_end()

Definition at line 310 of file ptr_set.c.

References ptr_set_end().

Referenced by configured_symbol_find().

Here is the call graph for this function:

bool ptr_set_equal ( ptr_set_const_h  lhs,
ptr_set_const_h  rhs 
)

Say whether two pointer sets are equal.

Parameters:
lhsThe first pointer set to compare.
rhsThe second pointer set to compare.
Returns:
True if both sets are NULL or if they have the same comparator member and are equal in the same sense as pointer vectors with respect to that comparator.

Definition at line 175 of file ptr_set.c.

References eq(), and ptr_vector_equal().

Here is the call graph for this function:

bool ptr_set_insert ( ptr_set_h  ps,
void const *  obj 
)

Insert an object into a pointer set.

Parameters:
psThe pointer set in which the object is to be inserted.
objAddress of the object to be inserted,
Returns:
If false if obj is already in the set. Otherwise obj is inserted and true is returned.

Definition at line 236 of file ptr_set.c.

References ptr_set::cached_pos, ptr_set::compare, NOWHERE, ptr_vector_append(), ptr_vector_at(), ptr_vector_count(), ptr_vector_insert(), ptr_vector_search(), ptr_set::pv, and SOMEWHERE.

Referenced by configured_symbol_add(), directive_text_add(), hash_include_add(), and unconfigured_symbol_tally().

Here is the call graph for this function:

ptr_set_h ptr_set_new ( comparator_t  compare,
dtor_t  dtor,
cloner_t  cloner 
)

Create new pointer set.

Parameters:
compareThe key comparison function for this pointer set, or NULL. If NULL then elements are compared by strcmp()
dtorThe destructor to be applied to set elements when the set is destroyed, or NULL. If NULL then free() is assumed.
clonerThe cloning function for cloning elements of this set, or NULL. If NULL then clone(ptr,0) is assumed.
Returns:
A new pointer set.

Definition at line 128 of file ptr_set.c.

References allocate(), and ptr_set_init().

Referenced by directive_text_lookup().

Here is the call graph for this function:

void* ptr_set_search ( ptr_set_h  ps,
char const *  key,
locator_t  keylen 
)

Search for a key value in a pointer set.

Parameters:
psThe pointer set to be searched.
keyStart of the key value to be searched for.
keylenIf postive this is the length of the key value to be searched for. If 0 or negative then key is in fact the address of an object that is to be searched for by key.
Returns:
If key is matched then the address of the matching element is returned; otherwise NULL.

If key is not found then ps caches the position at which this key would sort in ps. If the next operation on ps is to insert an obj that matches key then insertion can be highly optimised by localising the second search of the set to the neighbours of the cached position. If this optimisation fails because the object to be inserted next does not match the cached key then that object is inserted the long way.

The pointer returned by this function is invalidated by any subsequent non-const operation on ps.

If the return value is used to modify the key of the object it addresses then ps is corrupted.

Definition at line 215 of file ptr_set.c.

References ptr_set::cached_pos, ptr_set::compare, NOWHERE, ptr_vector_at(), ptr_vector_search(), and ptr_set::pv.

Referenced by configured_symbol_match_const(), directive_text_lookup(), hash_include_lookup(), ptr_set_search_const(), and unconfigured_symbol_tally().

Here is the call graph for this function:

void const* ptr_set_search_const ( ptr_set_const_h  ps,
char const *  key,
locator_t  keylen 
)

Const variant of ptr_set_search()

Definition at line 229 of file ptr_set.c.

References ptr_set_search().

Here is the call graph for this function:

void ptr_set_swap ( ptr_set_h  lhs,
ptr_set_h  rhs 
)

Exchange two pointer sets

Definition at line 155 of file ptr_set.c.

References ptr_set::cached_pos, ptr_set::compare, PODSWAP, ptr_vector_swap(), and ptr_set::pv.

Referenced by ptr_set_assign().

Here is the call graph for this function:

 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Defines