SVF
Classes | Macros | Typedefs | Enumerations | Functions
st.h File Reference

Go to the source code of this file.

Classes

struct  st_table_entry
 
struct  st_table
 
struct  st_generator
 

Macros

#define ST_DEFAULT_MAX_DENSITY   5
 
#define ST_DEFAULT_INIT_TABLE_SIZE   11
 
#define ST_DEFAULT_GROW_FACTOR   2.0
 
#define ST_DEFAULT_REORDER_FLAG   0
 
#define ST_OUT_OF_MEM   -10000
 
#define st_is_member(table, key)   st_lookup(table,key,(char **) 0)
 
#define st_count(table)   ((table)->num_entries)
 
#define st_foreach_item(table, gen, key, value)   for(gen=st_init_gen(table); st_gen(gen,key,value) || (st_free_gen(gen),0);)
 
#define st_foreach_item_int(table, gen, key, value)   for(gen=st_init_gen(table); st_gen_int(gen,key,value) || (st_free_gen(gen),0);)
 

Typedefs

typedef struct st_table_entry st_table_entry
 
typedef struct st_table st_table
 
typedef struct st_generator st_generator
 
typedef enum st_retval(* ST_PFSR) (char *, char *, char *)
 
typedef int(* ST_PFICPCP) (const char *, const char *)
 
typedef int(* ST_PFICPI) (char *, int)
 

Enumerations

enum  st_retval { ST_CONTINUE, ST_STOP, ST_DELETE }
 

Functions

st_tablest_init_table_with_params (ST_PFICPCP, ST_PFICPI, int, int, double, int)
 
st_tablest_init_table (ST_PFICPCP, ST_PFICPI)
 
void st_free_table (st_table *)
 
int st_lookup (st_table *, void *, void *)
 
int st_lookup_int (st_table *, void *, int *)
 
int st_insert (st_table *, void *, void *)
 
int st_add_direct (st_table *, void *, void *)
 
int st_find_or_add (st_table *, void *, void *)
 
int st_find (st_table *, void *, void *)
 
st_tablest_copy (st_table *)
 
int st_delete (st_table *, void *, void *)
 
int st_delete_int (st_table *, void *, int *)
 
int st_foreach (st_table *, ST_PFSR, char *)
 
int st_strhash (char *, int)
 
int st_numhash (char *, int)
 
int st_ptrhash (char *, int)
 
int st_numcmp (const char *, const char *)
 
int st_ptrcmp (const char *, const char *)
 
st_generatorst_init_gen (st_table *)
 
int st_gen (st_generator *, void *, void *)
 
int st_gen_int (st_generator *, void *, int *)
 
void st_free_gen (st_generator *)
 

Macro Definition Documentation

◆ st_count

#define st_count (   table)    ((table)->num_entries)

Macro***********************************************************************

Synopsis [Returns the number of entries in the table `table'.]

Description [Returns the number of entries in the table `table'.]

SideEffects [None]

SeeAlso []

Definition at line 121 of file st.h.

◆ ST_DEFAULT_GROW_FACTOR

#define ST_DEFAULT_GROW_FACTOR   2.0

Definition at line 39 of file st.h.

◆ ST_DEFAULT_INIT_TABLE_SIZE

#define ST_DEFAULT_INIT_TABLE_SIZE   11

Definition at line 38 of file st.h.

◆ ST_DEFAULT_MAX_DENSITY

#define ST_DEFAULT_MAX_DENSITY   5

CHeaderFile*****************************************************************

FileName [st.h]

PackageName [st]

Synopsis [Symbol table package.]

Description [The st library provides functions to create, maintain, and query symbol tables.]

SeeAlso []

Author []

Copyright []

Revision [

Id
st.h,v 1.10 2004/01/02 07:40:31 fabio Exp fabio

]

Definition at line 37 of file st.h.

◆ ST_DEFAULT_REORDER_FLAG

#define ST_DEFAULT_REORDER_FLAG   0

Definition at line 40 of file st.h.

◆ st_foreach_item

#define st_foreach_item (   table,
  gen,
  key,
  value 
)    for(gen=st_init_gen(table); st_gen(gen,key,value) || (st_free_gen(gen),0);)

Macro***********************************************************************

Synopsis [Iteration macro.]

Description [An iteration macro which loops over all the entries in `table', setting `key' to point to the key and `value' to the associated value (if it is not nil). `gen' is a generator variable used internally. Sample usage:

    char *key, *value;
  st_generator *gen;
  st_foreach_item(table, gen, &key, &value) {
      process_item(value);
  }

]

SideEffects [None]

SeeAlso [st_foreach_item_int st_foreach]

Definition at line 155 of file st.h.

◆ st_foreach_item_int

#define st_foreach_item_int (   table,
  gen,
  key,
  value 
)    for(gen=st_init_gen(table); st_gen_int(gen,key,value) || (st_free_gen(gen),0);)

Macro***********************************************************************

Synopsis [Iteration macro.]

Description [An iteration macro which loops over all the entries in `table', setting `key' to point to the key and `value' to the associated value (if it is not nil). `value' is assumed to be a pointer to an integer. `gen' is a generator variable used internally. Sample usage:

    char *key;
  int value;
  st_generator *gen;
  st_foreach_item_int(table, gen, &key, &value) {
      process_item(value);
  }

]

SideEffects [None]

SeeAlso [st_foreach_item st_foreach]

Definition at line 194 of file st.h.

◆ st_is_member

#define st_is_member (   table,
  key 
)    st_lookup(table,key,(char **) 0)

Macro***********************************************************************

Synopsis [Checks whethere `key' is in `table'.]

Description [Returns 1 if there is an entry under `key' in `table', 0 otherwise.]

SideEffects [None]

SeeAlso [st_lookup]

Definition at line 107 of file st.h.

◆ ST_OUT_OF_MEM

#define ST_OUT_OF_MEM   -10000

Definition at line 41 of file st.h.

Typedef Documentation

◆ st_generator

typedef struct st_generator st_generator

Definition at line 71 of file st.h.

◆ ST_PFICPCP

typedef int(* ST_PFICPCP) (const char *, const char *)

Definition at line 82 of file st.h.

◆ ST_PFICPI

typedef int(* ST_PFICPI) (char *, int)

Definition at line 84 of file st.h.

◆ ST_PFSR

typedef enum st_retval(* ST_PFSR) (char *, char *, char *)

Definition at line 80 of file st.h.

◆ st_table

typedef struct st_table st_table

Definition at line 59 of file st.h.

◆ st_table_entry

Definition at line 52 of file st.h.

Enumeration Type Documentation

◆ st_retval

enum st_retval
Enumerator
ST_CONTINUE 
ST_STOP 
ST_DELETE 

Definition at line 78 of file st.h.

Definition: st.h:78
Definition: st.h:78
Definition: st.h:78

Function Documentation

◆ st_add_direct()

int st_add_direct ( st_table table,
void *  key,
void *  value 
)

Function********************************************************************

Synopsis [Place 'value' in 'table' under the key 'key'.]

Description [Place 'value' in 'table' under the key 'key'. This is done without checking if 'key' is in 'table' already. This should only be used if you are sure there is not already an entry for 'key', since it is undefined which entry you would later get from st_lookup or st_find_or_add. Returns 1 if successful; ST_OUT_OF_MEM otherwise.]

SideEffects [None]

SeeAlso []

Definition at line 410 of file st.c.

411 {
412  int hash_val;
413  st_table_entry *newt;
414 
415  hash_val = do_hash(key, table);
416  if (table->num_entries / table->num_bins >= table->max_density) {
417  if (rehash(table) == ST_OUT_OF_MEM) {
418  return ST_OUT_OF_MEM;
419  }
420  }
421  hash_val = do_hash(key, table);
422  newt = ALLOC(st_table_entry, 1);
423  if (newt == NIL(st_table_entry)) {
424  return ST_OUT_OF_MEM;
425  }
426  newt->key = (char *)key;
427  newt->record = (char *)value;
428  newt->next = table->bins[hash_val];
429  table->bins[hash_val] = newt;
430  table->num_entries++;
431  return 1;
432 
433 } /* st_add_direct */
int num_bins
Definition: st.h:63
st_table_entry * next
Definition: st.h:56
int max_density
Definition: st.h:65
int num_entries
Definition: st.h:64
Definition: st.h:53
#define NIL(type)
Definition: util.h:44
#define ALLOC(type, num)
Definition: util.h:76
#define ST_OUT_OF_MEM
Definition: st.h:41
char * record
Definition: st.h:55
char * key
Definition: st.h:54
#define do_hash(key, table)
Definition: st.c:63
st_table_entry ** bins
Definition: st.h:68
static int rehash(st_table *)
Definition: st.c:1021

◆ st_copy()

st_table* st_copy ( st_table old_table)

Function********************************************************************

Synopsis [Return a copy of old_table and all its members.]

Description [Return a copy of old_table and all its members. (st_table *) 0 is returned if there was insufficient memory to do the copy.]

SideEffects [None]

SeeAlso []

Definition at line 571 of file st.c.

572 {
573  st_table *new_table;
574  st_table_entry *ptr, *newptr, *next, *newt;
575  int i, j, num_bins = old_table->num_bins;
576 
577  new_table = ALLOC(st_table, 1);
578  if (new_table == NIL(st_table)) {
579  return NIL(st_table);
580  }
581 
582  *new_table = *old_table;
583  new_table->bins = ALLOC(st_table_entry *, num_bins);
584  if (new_table->bins == NIL(st_table_entry *)) {
585  FREE(new_table);
586  return NIL(st_table);
587  }
588  for(i = 0; i < num_bins ; i++) {
589  new_table->bins[i] = NIL(st_table_entry);
590  ptr = old_table->bins[i];
591  while (ptr != NIL(st_table_entry)) {
592  newt = ALLOC(st_table_entry, 1);
593  if (newt == NIL(st_table_entry)) {
594  for (j = 0; j <= i; j++) {
595  newptr = new_table->bins[j];
596  while (newptr != NIL(st_table_entry)) {
597  next = newptr->next;
598  FREE(newptr);
599  newptr = next;
600  }
601  }
602  FREE(new_table->bins);
603  FREE(new_table);
604  return NIL(st_table);
605  }
606  *newt = *ptr;
607  newt->next = new_table->bins[i];
608  new_table->bins[i] = newt;
609  ptr = ptr->next;
610  }
611  }
612  return new_table;
613 
614 } /* st_copy */
int num_bins
Definition: st.h:63
Definition: st.h:60
#define FREE(obj)
Definition: util.h:80
st_table_entry * next
Definition: st.h:56
Definition: st.h:53
#define NIL(type)
Definition: util.h:44
#define ALLOC(type, num)
Definition: util.h:76
st_table_entry ** bins
Definition: st.h:68

◆ st_delete()

int st_delete ( st_table table,
void *  keyp,
void *  value 
)

Function********************************************************************

Synopsis [Delete the entry with the key pointed to by `keyp'.]

Description [Delete the entry with the key pointed to by `keyp'. If the entry is found, 1 is returned, the variable pointed by `keyp' is set to the actual key and the variable pointed by `value' is set to the corresponding entry. (This allows the freeing of the associated storage.) If the entry is not found, then 0 is returned and nothing is changed.]

SideEffects [None]

SeeAlso [st_delete_int]

Definition at line 634 of file st.c.

635 {
636  int hash_val;
637  char *key = *(char **)keyp;
638  st_table_entry *ptr, **last;
639 
640  hash_val = do_hash(key, table);
641 
642  FIND_ENTRY(table, hash_val, key, ptr ,last);
643 
644  if (ptr == NIL(st_table_entry)) {
645  return 0;
646  }
647 
648  *last = ptr->next;
649  if (value != NIL(void)) *(char **)value = ptr->record;
650  *(char **)keyp = ptr->key;
651  FREE(ptr);
652  table->num_entries--;
653  return 1;
654 
655 } /* st_delete */
#define FREE(obj)
Definition: util.h:80
#define FIND_ENTRY(table, hash_val, key, ptr, last)
Definition: st.c:71
st_table_entry * next
Definition: st.h:56
int num_entries
Definition: st.h:64
Definition: st.h:53
#define NIL(type)
Definition: util.h:44
char * record
Definition: st.h:55
char * key
Definition: st.h:54
#define do_hash(key, table)
Definition: st.c:63

◆ st_delete_int()

int st_delete_int ( st_table table,
void *  keyp,
int *  value 
)

Function********************************************************************

Synopsis [Delete the entry with the key pointed to by `keyp'.]

Description [Delete the entry with the key pointed to by `keyp'. `value' must be a pointer to an integer. If the entry is found, 1 is returned, the variable pointed by `keyp' is set to the actual key and the variable pointed by `value' is set to the corresponding entry. (This allows the freeing of the associated storage.) If the entry is not found, then 0 is returned and nothing is changed.]

SideEffects [None]

SeeAlso [st_delete]

Definition at line 675 of file st.c.

676 {
677  int hash_val;
678  char *key = *(char **)keyp;
679  st_table_entry *ptr, **last;
680 
681  hash_val = do_hash(key, table);
682 
683  FIND_ENTRY(table, hash_val, key, ptr ,last);
684 
685  if (ptr == NIL(st_table_entry)) {
686  return 0;
687  }
688 
689  *last = ptr->next;
690  if (value != NIL(int)) *value = (int) (long) ptr->record;
691  *(char **)keyp = ptr->key;
692  FREE(ptr);
693  table->num_entries--;
694  return 1;
695 
696 } /* st_delete_int */
#define FREE(obj)
Definition: util.h:80
#define FIND_ENTRY(table, hash_val, key, ptr, last)
Definition: st.c:71
st_table_entry * next
Definition: st.h:56
int num_entries
Definition: st.h:64
Definition: st.h:53
#define NIL(type)
Definition: util.h:44
char * record
Definition: st.h:55
char * key
Definition: st.h:54
#define do_hash(key, table)
Definition: st.c:63

◆ st_find()

int st_find ( st_table table,
void *  key,
void *  slot 
)

Function********************************************************************

Synopsis [Lookup `key' in `table'.]

Description [Like st_find_or_add, but does not create an entry if one is not found.]

SideEffects [None]

SeeAlso [st_find_or_add]

Definition at line 536 of file st.c.

537 {
538  int hash_val;
539  st_table_entry *ptr, **last;
540 
541  hash_val = do_hash(key, table);
542 
543  FIND_ENTRY(table, hash_val, key, ptr, last);
544 
545  if (ptr == NIL(st_table_entry)) {
546  return 0;
547  } else {
548  if (slot != NIL(void)) {
549  *(char ***)slot = &ptr->record;
550  }
551  return 1;
552  }
553 
554 } /* st_find */
#define FIND_ENTRY(table, hash_val, key, ptr, last)
Definition: st.c:71
Definition: st.h:53
#define NIL(type)
Definition: util.h:44
char * record
Definition: st.h:55
#define do_hash(key, table)
Definition: st.c:63

◆ st_find_or_add()

int st_find_or_add ( st_table table,
void *  key,
void *  slot 
)

Function********************************************************************

Synopsis [Lookup `key' in `table'.]

Description [Lookup `key' in `table'. If not found, create an entry. In either case set slot to point to the field in the entry where the value is stored. The value associated with `key' may then be changed by accessing directly through slot. Returns 1 if an entry already existed, 0 if it did not exist and creation was successful; ST_OUT_OF_MEM otherwise. As an example:

    char **slot;
    char *key;
    char *value = (char *) item_ptr <-- ptr to a malloc'd structure
    if (st_find_or_add(table, key, &slot) == 1) {
   FREE(*slot); <-- free the old value of the record
    }
    *slot = value;  <-- attach the new value to the record

This replaces the equivelent code:

    if (st_lookup(table, key, &ovalue) == 1) {
       FREE(ovalue);
    }
    st_insert(table, key, value);

]

SideEffects [None]

SeeAlso [st_find]

Definition at line 488 of file st.c.

489 {
490  int hash_val;
491  st_table_entry *newt, *ptr, **last;
492 
493  hash_val = do_hash(key, table);
494 
495  FIND_ENTRY(table, hash_val, key, ptr, last);
496 
497  if (ptr == NIL(st_table_entry)) {
498  if (table->num_entries / table->num_bins >= table->max_density) {
499  if (rehash(table) == ST_OUT_OF_MEM) {
500  return ST_OUT_OF_MEM;
501  }
502  hash_val = do_hash(key, table);
503  }
504  newt = ALLOC(st_table_entry, 1);
505  if (newt == NIL(st_table_entry)) {
506  return ST_OUT_OF_MEM;
507  }
508  newt->key = (char *)key;
509  newt->record = (char *) 0;
510  newt->next = table->bins[hash_val];
511  table->bins[hash_val] = newt;
512  table->num_entries++;
513  if (slot != NIL(void)) *(char ***)slot = &newt->record;
514  return 0;
515  } else {
516  if (slot != NIL(void)) *(char ***)slot = &ptr->record;
517  return 1;
518  }
519 
520 } /* st_find_or_add */
int num_bins
Definition: st.h:63
#define FIND_ENTRY(table, hash_val, key, ptr, last)
Definition: st.c:71
st_table_entry * next
Definition: st.h:56
int max_density
Definition: st.h:65
int num_entries
Definition: st.h:64
Definition: st.h:53
#define NIL(type)
Definition: util.h:44
#define ALLOC(type, num)
Definition: util.h:76
#define ST_OUT_OF_MEM
Definition: st.h:41
char * record
Definition: st.h:55
char * key
Definition: st.h:54
#define do_hash(key, table)
Definition: st.c:63
st_table_entry ** bins
Definition: st.h:68
static int rehash(st_table *)
Definition: st.c:1021

◆ st_foreach()

int st_foreach ( st_table table,
ST_PFSR  func,
char *  arg 
)

Function********************************************************************

Synopsis [Iterates over the elements of a table.]

Description [For each (key, value) record in `table', st_foreach call func with the arguments

    (*func)(key, value, arg)

If func returns ST_CONTINUE, st_foreach continues processing entries. If func returns ST_STOP, st_foreach stops processing and returns immediately. If func returns ST_DELETE, then the entry is deleted from the symbol table and st_foreach continues. In the case of ST_DELETE, it is func's responsibility to free the key and value, if necessary.

The routine returns 1 if all items in the table were generated and 0 if the generation sequence was aborted using ST_STOP. The order in which the records are visited will be seemingly random.]

SideEffects [None]

SeeAlso [st_foreach_item st_foreach_item_int]

Definition at line 725 of file st.c.

726 {
727  st_table_entry *ptr, **last;
728  enum st_retval retval;
729  int i;
730 
731  for(i = 0; i < table->num_bins; i++) {
732  last = &table->bins[i]; ptr = *last;
733  while (ptr != NIL(st_table_entry)) {
734  retval = (*func)(ptr->key, ptr->record, arg);
735  switch (retval) {
736  case ST_CONTINUE:
737  last = &ptr->next; ptr = *last;
738  break;
739  case ST_STOP:
740  return 0;
741  case ST_DELETE:
742  *last = ptr->next;
743  table->num_entries--; /* cstevens@ic */
744  FREE(ptr);
745  ptr = *last;
746  }
747  }
748  }
749  return 1;
750 
751 } /* st_foreach */
Definition: st.h:78
int num_bins
Definition: st.h:63
Definition: st.h:78
#define FREE(obj)
Definition: util.h:80
Definition: st.h:78
st_table_entry * next
Definition: st.h:56
int num_entries
Definition: st.h:64
Definition: st.h:53
#define NIL(type)
Definition: util.h:44
st_retval
Definition: st.h:78
char * record
Definition: st.h:55
char * key
Definition: st.h:54
st_table_entry ** bins
Definition: st.h:68

◆ st_free_gen()

void st_free_gen ( st_generator gen)

Function********************************************************************

Synopsis [Reclaims the resources associated with `gen'.]

Description [After generating all items in a generation sequence, this routine must be called to reclaim the resources associated with `gen'.]

SideEffects [None]

SeeAlso [st_init_gen]

Definition at line 994 of file st.c.

995 {
996  FREE(gen);
997 
998 } /* st_free_gen */
#define FREE(obj)
Definition: util.h:80

◆ st_free_table()

void st_free_table ( st_table table)

Function********************************************************************

Synopsis [Free a table.]

Description [Any internal storage associated with table is freed. It is the user's responsibility to free any storage associated with the pointers he placed in the table (by perhaps using st_foreach).]

SideEffects [None]

SeeAlso [st_init_table st_init_table_with_params]

Definition at line 252 of file st.c.

253 {
254  st_table_entry *ptr, *next;
255  int i;
256 
257  for(i = 0; i < table->num_bins ; i++) {
258  ptr = table->bins[i];
259  while (ptr != NIL(st_table_entry)) {
260  next = ptr->next;
261  FREE(ptr);
262  ptr = next;
263  }
264  }
265  FREE(table->bins);
266  FREE(table);
267 
268 } /* st_free_table */
int num_bins
Definition: st.h:63
#define FREE(obj)
Definition: util.h:80
st_table_entry * next
Definition: st.h:56
Definition: st.h:53
#define NIL(type)
Definition: util.h:44
st_table_entry ** bins
Definition: st.h:68

◆ st_gen()

int st_gen ( st_generator gen,
void *  key_p,
void *  value_p 
)

Function********************************************************************

Synopsis [returns the next (key, value) pair in the generation sequence. ]

Description [Given a generator returned by st_init_gen(), this routine returns the next (key, value) pair in the generation sequence. The pointer `value_p' can be zero which means no value will be returned. When there are no more items in the generation sequence, the routine returns 0.

While using a generation sequence, deleting any (key, value) pair other than the one just generated may cause a fatal error when st_gen() is called later in the sequence and is therefore not recommended.]

SideEffects [None]

SeeAlso [st_gen_int]

Definition at line 908 of file st.c.

909 {
910  int i;
911 
912  if (gen->entry == NIL(st_table_entry)) {
913  /* try to find next entry */
914  for(i = gen->index; i < gen->table->num_bins; i++) {
915  if (gen->table->bins[i] != NIL(st_table_entry)) {
916  gen->index = i+1;
917  gen->entry = gen->table->bins[i];
918  break;
919  }
920  }
921  if (gen->entry == NIL(st_table_entry)) {
922  return 0; /* that's all folks ! */
923  }
924  }
925  *(char **)key_p = gen->entry->key;
926  if (value_p != NIL(void)) {
927  *(char **)value_p = gen->entry->record;
928  }
929  gen->entry = gen->entry->next;
930  return 1;
931 
932 } /* st_gen */
st_table_entry * next
Definition: st.h:56
st_table * table
Definition: st.h:73
Definition: st.h:53
#define NIL(type)
Definition: util.h:44
int index
Definition: st.h:75
char * record
Definition: st.h:55
char * key
Definition: st.h:54
st_table_entry ** bins
Definition: st.h:68
st_table_entry * entry
Definition: st.h:74
if(DEFINED IN_SOURCE_BUILD) set(LLVM_LINK_COMPONENTS BitWriter Core IPO IrReader InstCombine Instrumentation Target Linker Analysis ScalarOpts Support Svf Cudd) add_llvm_tool(dvf dda.cpp) else() add_executable(dvf dda.cpp) target_link_libraries(dvf Svf Cudd $
Definition: CMakeLists.txt:2

◆ st_gen_int()

int st_gen_int ( st_generator gen,
void *  key_p,
int *  value_p 
)

Function********************************************************************

Synopsis [Returns the next (key, value) pair in the generation sequence.]

Description [Given a generator returned by st_init_gen(), this routine returns the next (key, value) pair in the generation sequence. `value_p' must be a pointer to an integer. The pointer `value_p' can be zero which means no value will be returned. When there are no more items in the generation sequence, the routine returns 0.]

SideEffects [None]

SeeAlso [st_gen]

Definition at line 953 of file st.c.

954 {
955  int i;
956 
957  if (gen->entry == NIL(st_table_entry)) {
958  /* try to find next entry */
959  for(i = gen->index; i < gen->table->num_bins; i++) {
960  if (gen->table->bins[i] != NIL(st_table_entry)) {
961  gen->index = i+1;
962  gen->entry = gen->table->bins[i];
963  break;
964  }
965  }
966  if (gen->entry == NIL(st_table_entry)) {
967  return 0; /* that's all folks ! */
968  }
969  }
970  *(char **)key_p = gen->entry->key;
971  if (value_p != NIL(int)) {
972  *value_p = (int) (long) gen->entry->record;
973  }
974  gen->entry = gen->entry->next;
975  return 1;
976 
977 } /* st_gen_int */
st_table_entry * next
Definition: st.h:56
st_table * table
Definition: st.h:73
Definition: st.h:53
#define NIL(type)
Definition: util.h:44
int index
Definition: st.h:75
char * record
Definition: st.h:55
char * key
Definition: st.h:54
st_table_entry ** bins
Definition: st.h:68
st_table_entry * entry
Definition: st.h:74
if(DEFINED IN_SOURCE_BUILD) set(LLVM_LINK_COMPONENTS BitWriter Core IPO IrReader InstCombine Instrumentation Target Linker Analysis ScalarOpts Support Svf Cudd) add_llvm_tool(dvf dda.cpp) else() add_executable(dvf dda.cpp) target_link_libraries(dvf Svf Cudd $
Definition: CMakeLists.txt:2

◆ st_init_gen()

st_generator* st_init_gen ( st_table table)

Function********************************************************************

Synopsis [Initializes a generator.]

Description [Returns a generator handle which when used with st_gen() will progressively return each (key, value) record in `table'.]

SideEffects [None]

SeeAlso [st_free_gen]

Definition at line 870 of file st.c.

871 {
872  st_generator *gen;
873 
874  gen = ALLOC(st_generator, 1);
875  if (gen == NIL(st_generator)) {
876  return NIL(st_generator);
877  }
878  gen->table = table;
879  gen->entry = NIL(st_table_entry);
880  gen->index = 0;
881  return gen;
882 
883 } /* st_init_gen */
st_table * table
Definition: st.h:73
Definition: st.h:53
#define NIL(type)
Definition: util.h:44
#define ALLOC(type, num)
Definition: util.h:76
int index
Definition: st.h:75
st_table_entry * entry
Definition: st.h:74

◆ st_init_table()

st_table* st_init_table ( ST_PFICPCP  compare,
ST_PFICPI  hash 
)

AutomaticEnd Function********************************************************************

Synopsis [Create and initialize a table.]

Description [Create and initialize a table with the comparison function compare_fn and hash function hash_fn. compare_fn is

  int compare_fn(const char *key1, const char *key2)

It returns <,=,> 0 depending on whether key1 <,=,> key2 by some measure.

hash_fn is

  int hash_fn(char *key, int modulus)

It returns a integer between 0 and modulus-1 such that if compare_fn(key1,key2) == 0 then hash_fn(key1) == hash_fn(key2).

There are five predefined hash and comparison functions in st. For keys as numbers:

   st_numhash(key, modulus) { return (unsigned int) key % modulus; }
   st_numcmp(x,y) { return (int) x - (int) y; }

For keys as pointers:

   st_ptrhash(key, modulus) { return ((unsigned int) key/4) % modulus }
   st_ptrcmp(x,y) { return (int) x - (int) y; }

For keys as strings:

       st_strhash(x,y) - a reasonable hashing function for strings
   strcmp(x,y) - the standard library function

It is recommended to use these particular functions if they fit your needs, since st will recognize certain of them and run more quickly because of it.]

SideEffects [None]

SeeAlso [st_init_table_with_params st_free_table]

Definition at line 163 of file st.c.

164 {
169 
170 } /* st_init_table */
#define ST_DEFAULT_REORDER_FLAG
Definition: st.h:40
st_table * st_init_table_with_params(ST_PFICPCP compare, ST_PFICPI hash, int size, int density, double grow_factor, int reorder_flag)
Definition: st.c:199
#define ST_DEFAULT_MAX_DENSITY
Definition: st.h:37
#define ST_DEFAULT_GROW_FACTOR
Definition: st.h:39
#define ST_DEFAULT_INIT_TABLE_SIZE
Definition: st.h:38

◆ st_init_table_with_params()

st_table* st_init_table_with_params ( ST_PFICPCP  compare,
ST_PFICPI  hash,
int  size,
int  density,
double  grow_factor,
int  reorder_flag 
)

AutomaticStart

Function********************************************************************

Synopsis [Create a table with given parameters.]

Description [The full blown table initializer. compare and hash are the same as in st_init_table. density is the largest the average number of entries per hash bin there should be before the table is grown. grow_factor is the factor the table is grown by when it becomes too full. size is the initial number of bins to be allocated for the hash table. If reorder_flag is non-zero, then every time an entry is found, it is moved to the top of the chain.

st_init_table(compare, hash) is equivelent to

st_init_table_with_params(compare, hash, ST_DEFAULT_INIT_TABLE_SIZE,
            ST_DEFAULT_MAX_DENSITY,
            ST_DEFAULT_GROW_FACTOR,
            ST_DEFAULT_REORDER_FLAG);

]

SideEffects [None]

SeeAlso [st_init_table st_free_table]

Definition at line 199 of file st.c.

206 {
207  int i;
208  st_table *newt;
209 
210  newt = ALLOC(st_table, 1);
211  if (newt == NIL(st_table)) {
212  return NIL(st_table);
213  }
214  newt->compare = compare;
215  newt->hash = hash;
216  newt->num_entries = 0;
217  newt->max_density = density;
218  newt->grow_factor = grow_factor;
219  newt->reorder_flag = reorder_flag;
220  if (size <= 0) {
221  size = 1;
222  }
223  newt->num_bins = size;
224  newt->bins = ALLOC(st_table_entry *, size);
225  if (newt->bins == NIL(st_table_entry *)) {
226  FREE(newt);
227  return NIL(st_table);
228  }
229  for(i = 0; i < size; i++) {
230  newt->bins[i] = 0;
231  }
232  return newt;
233 
234 } /* st_init_table_with_params */
int num_bins
Definition: st.h:63
Definition: st.h:60
#define FREE(obj)
Definition: util.h:80
int max_density
Definition: st.h:65
int(* hash)(char *, int)
Definition: st.h:62
int num_entries
Definition: st.h:64
Definition: st.h:53
double grow_factor
Definition: st.h:67
#define NIL(type)
Definition: util.h:44
#define ALLOC(type, num)
Definition: util.h:76
int(* compare)(const char *, const char *)
Definition: st.h:61
st_table_entry ** bins
Definition: st.h:68
int reorder_flag
Definition: st.h:66

◆ st_insert()

int st_insert ( st_table table,
void *  key,
void *  value 
)

Function********************************************************************

Synopsis [Insert value in table under the key 'key'.]

Description [Insert value in table under the key 'key'. Returns 1 if there was an entry already under the key; 0 if there was no entry under the key and insertion was successful; ST_OUT_OF_MEM otherwise. In either of the first two cases the new value is added.]

SideEffects [None]

SeeAlso []

Definition at line 358 of file st.c.

359 {
360  int hash_val;
361  st_table_entry *newt;
362  st_table_entry *ptr, **last;
363 
364  hash_val = do_hash(key, table);
365 
366  FIND_ENTRY(table, hash_val, key, ptr, last);
367 
368  if (ptr == NIL(st_table_entry)) {
369  if (table->num_entries/table->num_bins >= table->max_density) {
370  if (rehash(table) == ST_OUT_OF_MEM) {
371  return ST_OUT_OF_MEM;
372  }
373  hash_val = do_hash(key, table);
374  }
375  newt = ALLOC(st_table_entry, 1);
376  if (newt == NIL(st_table_entry)) {
377  return ST_OUT_OF_MEM;
378  }
379  newt->key = (char *)key;
380  newt->record = (char *)value;
381  newt->next = table->bins[hash_val];
382  table->bins[hash_val] = newt;
383  table->num_entries++;
384  return 0;
385  } else {
386  ptr->record = (char *)value;
387  return 1;
388  }
389 
390 } /* st_insert */
int num_bins
Definition: st.h:63
#define FIND_ENTRY(table, hash_val, key, ptr, last)
Definition: st.c:71
st_table_entry * next
Definition: st.h:56
int max_density
Definition: st.h:65
int num_entries
Definition: st.h:64
Definition: st.h:53
#define NIL(type)
Definition: util.h:44
#define ALLOC(type, num)
Definition: util.h:76
#define ST_OUT_OF_MEM
Definition: st.h:41
char * record
Definition: st.h:55
char * key
Definition: st.h:54
#define do_hash(key, table)
Definition: st.c:63
st_table_entry ** bins
Definition: st.h:68
static int rehash(st_table *)
Definition: st.c:1021

◆ st_lookup()

int st_lookup ( st_table table,
void *  key,
void *  value 
)

Function********************************************************************

Synopsis [Lookup up `key' in `table'.]

Description [Lookup up `key' in `table'. If an entry is found, 1 is returned and if `value' is not nil, the variable it points to is set to the associated value. If an entry is not found, 0 is returned and the variable pointed by value is unchanged.]

SideEffects [None]

SeeAlso [st_lookup_int]

Definition at line 286 of file st.c.

287 {
288  int hash_val;
289  st_table_entry *ptr, **last;
290 
291  hash_val = do_hash(key, table);
292 
293  FIND_ENTRY(table, hash_val, key, ptr, last);
294 
295  if (ptr == NIL(st_table_entry)) {
296  return 0;
297  } else {
298  if (value != NIL(void)) {
299  *(char **)value = ptr->record;
300  }
301  return 1;
302  }
303 
304 } /* st_lookup */
#define FIND_ENTRY(table, hash_val, key, ptr, last)
Definition: st.c:71
Definition: st.h:53
#define NIL(type)
Definition: util.h:44
char * record
Definition: st.h:55
#define do_hash(key, table)
Definition: st.c:63

◆ st_lookup_int()

int st_lookup_int ( st_table table,
void *  key,
int *  value 
)

Function********************************************************************

Synopsis [Lookup up `key' in `table'.]

Description [Lookup up `key' in `table'. If an entry is found, 1 is returned and if `value' is not nil, the variable it points to is set to the associated integer value. If an entry is not found, 0 is return and the variable pointed by `value' is unchanged.]

SideEffects [None]

SeeAlso [st_lookup]

Definition at line 322 of file st.c.

323 {
324  int hash_val;
325  st_table_entry *ptr, **last;
326 
327  hash_val = do_hash(key, table);
328 
329  FIND_ENTRY(table, hash_val, key, ptr, last);
330 
331  if (ptr == NIL(st_table_entry)) {
332  return 0;
333  } else {
334  if (value != NIL(int)) {
335  *value = (int) (long) ptr->record;
336  }
337  return 1;
338  }
339 
340 } /* st_lookup_int */
#define FIND_ENTRY(table, hash_val, key, ptr, last)
Definition: st.c:71
Definition: st.h:53
#define NIL(type)
Definition: util.h:44
char * record
Definition: st.h:55
#define do_hash(key, table)
Definition: st.c:63

◆ st_numcmp()

int st_numcmp ( const char *  x,
const char *  y 
)

Function********************************************************************

Synopsis [Number comparison function.]

Description [integer number comparison function.]

SideEffects [None]

SeeAlso [st_init_table st_numhash]

Definition at line 830 of file st.c.

831 {
832  return ST_NUMCMP(x, y);
833 
834 } /* st_numcmp */
#define ST_NUMCMP(x, y)
Definition: st.c:47

◆ st_numhash()

int st_numhash ( char *  x,
int  size 
)

Function********************************************************************

Synopsis [Number hash function.]

Description [Integer number hash function.]

SideEffects [None]

SeeAlso [st_init_table st_numcmp]

Definition at line 792 of file st.c.

793 {
794  return ST_NUMHASH(x, size);
795 
796 } /* st_numhash */
#define ST_NUMHASH(x, size)
Definition: st.c:49

◆ st_ptrcmp()

int st_ptrcmp ( const char *  x,
const char *  y 
)

Function********************************************************************

Synopsis [Pointer comparison function.]

Description [Pointer comparison function.]

SideEffects [None]

SeeAlso [st_init_table st_ptrhash]

Definition at line 849 of file st.c.

850 {
851  return ST_NUMCMP(x, y);
852 
853 } /* st_ptrcmp */
#define ST_NUMCMP(x, y)
Definition: st.c:47

◆ st_ptrhash()

int st_ptrhash ( char *  x,
int  size 
)

Function********************************************************************

Synopsis [Pointer hash function.]

Description [Pointer hash function.]

SideEffects [None]

SeeAlso [st_init_table st_ptrcmp]

Definition at line 811 of file st.c.

812 {
813  return ST_PTRHASH(x, size);
814 
815 } /* st_ptrhash */
#define ST_PTRHASH(x, size)
Definition: st.c:57

◆ st_strhash()

int st_strhash ( char *  string,
int  modulus 
)

Function********************************************************************

Synopsis [String hash function.]

Description [String hash function.]

SideEffects [None]

SeeAlso [st_init_table]

Definition at line 766 of file st.c.

767 {
768  int val = 0;
769  int c;
770 
771  while ((c = *string++) != '\0') {
772  val = val*997 + c;
773  }
774 
775  return ((val < 0) ? -val : val)%modulus;
776 
777 } /* st_strhash */