ceptr
 All Data Structures Files Functions Variables Typedefs Macros Modules Pages
scape.c
Go to the documentation of this file.
1 
11 #include "scape.h"
12 
23 Scape *_s_new(Symbol key_source,Symbol data_source) {
24  Scape *s = malloc(sizeof(Scape));
25  s->key_source = key_source;
26  s->data_source = data_source;
27  s->data = NULL;
28  return s;
29 }
30 
31 // free the hash table data
32 void scapedataFree(ScapeData *i) {
33  scape_elem *cur,*tmp;
34  HASH_ITER(hh, *i, cur, tmp) {
35  HASH_DEL(*i,cur); /* delete; cur advances to next */
36  free(cur);
37  }
38 }
39 
43 void _s_free(Scape *s) {
44  scapedataFree(&s->data);
45  free(s);
46 }
57 void _s_add(Scape *s,TreeHash h,Xaddr x) {
58  ScapeData *data = &s->data;
59  scape_elem *e;
60 
61  HASH_FIND_INT( *data, &h, e );
62  if (e) {
63  raise_error("allready there!");
64  }
65  else {
66  e = malloc(sizeof(struct scape_elem));
67  e->key = h;
68  e->value = x;
69  HASH_ADD_INT(*data,key,e);
70  }
71 }
72 
83 Xaddr _s_get(Scape *s,TreeHash h) {
84  Xaddr x = {0,0};
85  scape_elem *e = 0;
86  ScapeData *data = &s->data;
87 
88  HASH_FIND_INT( *data, &h, e );
89  if (e) return e->value;
90  return x;
91 }
92 
Scape * _s_new(Symbol key_source, Symbol data_source)
Definition: scape.c:23
Xaddr _s_get(Scape *s, TreeHash h)
Definition: scape.c:83
TreeHash key
has of the key tree that maps to a given data value
Definition: ceptr_types.h:280
ScapeData data
the scape data store (hash table)
Definition: ceptr_types.h:294
void _s_free(Scape *s)
Definition: scape.c:43
Xaddr value
instance of data_source pointed to by the key
Definition: ceptr_types.h:281
scape header files
void _s_add(Scape *s, TreeHash h, Xaddr x)
Definition: scape.c:57