ceptr
 All Data Structures Files Functions Variables Typedefs Macros Modules Pages
scape.c File Reference

implementation of scapes More...

#include "scape.h"
Include dependency graph for scape.c:

Go to the source code of this file.

Functions

Scape_s_new (Symbol key_source, Symbol data_source)
 
void scapedataFree (ScapeData *i)
 
void _s_free (Scape *s)
 
void _s_add (Scape *s, TreeHash h, Xaddr x)
 
Xaddr _s_get (Scape *s, TreeHash h)
 

Detailed Description

implementation of scapes

Definition in file scape.c.

Function Documentation

void _s_add ( Scape s,
TreeHash  h,
Xaddr  x 
)

add a new element into a scape

[in] s the scape [in] h a hash of the tree node which is the key [in] xaddr the instance address to be scaped

Examples (from test suite):

Scape *s = _s_new(TEST_INT_SYMBOL,TEST_STR_SYMBOL);
Xaddr x = {1,3}; // DUMMY XADDR
T *t = _t_newi(0,TEST_INT_SYMBOL,31415);
TreeHash h = _t_hash(G_sem,t);
_s_add(s,h,x);
// check that element was added
Xaddr xg = _s_get(s,h);
spec_is_sem_equal(xg.symbol,x.symbol);
spec_is_equal(xg.addr,x.addr);
// check that a different hash returns the null xaddr
t->contents.symbol = TEST_INT_SYMBOL2;
h = _t_hash(G_sem,t);
xg = _s_get(s,h);
spec_is_true(is_null_xaddr(xg));
_s_free(s);
_t_free(t);

Definition at line 57 of file scape.c.

void _s_free ( Scape s)

free the memory allocated to a scape

Definition at line 43 of file scape.c.

Xaddr _s_get ( Scape s,
TreeHash  h 
)

retrieve an Xaddr from the scape

[in] s the scape [in] key the tree node which is the key

Returns
Xaddr to the scape item

Examples (from test suite):

Scape *s = _s_new(TEST_INT_SYMBOL,TEST_STR_SYMBOL);
Xaddr x = {1,3}; // DUMMY XADDR
T *t = _t_newi(0,TEST_INT_SYMBOL,31415);
TreeHash h = _t_hash(G_sem,t);
_s_add(s,h,x);
// check that element was added
Xaddr xg = _s_get(s,h);
spec_is_sem_equal(xg.symbol,x.symbol);
spec_is_equal(xg.addr,x.addr);
// check that a different hash returns the null xaddr
t->contents.symbol = TEST_INT_SYMBOL2;
h = _t_hash(G_sem,t);
xg = _s_get(s,h);
spec_is_true(is_null_xaddr(xg));
_s_free(s);
_t_free(t);

Definition at line 83 of file scape.c.

Scape* _s_new ( Symbol  key_source,
Symbol  data_source 
)

create a new scape

[in] key_source the symbol type key hashes are of [in] data_source the symbol type of xaddrs to be associated with keys

Returns
a pointer to a newly allocated Scape

Examples (from test suite):

Scape *s = _s_new(TEST_INT_SYMBOL,TEST_STR_SYMBOL);
spec_is_symbol_equal(0,s->key_source,TEST_INT_SYMBOL);
spec_is_symbol_equal(0,s->data_source,TEST_STR_SYMBOL);
_s_free(s);

Definition at line 23 of file scape.c.