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

semantic tree matrix implementation More...

#include "mtree.h"
#include "ceptr_error.h"
#include "hashfn.h"
#include "def.h"
Include dependency graph for mtree.c:

Go to the source code of this file.

const H null_H = {0,{NULL_ADDR,NULL_ADDR}}
 
void __m_add_level (M *m)
 
N__m_add_nodes (H h, L *l, int c)
 
void __m_new_init (H parent, H *h, L **l)
 
void __m_new_root (H *h, L **l)
 
H __m_new (H parent, Symbol symbol, void *surface, size_t size, uint32_t flags)
 
H _m_new_root (Symbol s)
 
H _m_newr (H parent, Symbol s)
 
H _m_newi (H parent, Symbol symbol, int surface)
 
H __mnft (H parent, T *t)
 
H _m_new_from_t (T *t)
 
void _m_2tfn (H h, N *n, void *data, MwalkState *s, Maddr ap)
 
T_t_new_from_m (H h)
 
N__m_get (H h)
 
size_t _m_size (H h)
 
void __m_free (H h, int free_surface)
 
int _m_children (H h)
 
void * _m_surface (H h)
 
Maddr _m_parent (H h)
 
Maddr _m_child (H h, Mindex c)
 
Symbol _m_symbol (H h)
 
Maddr _m_next_sibling (H h)
 
H _m_add (H parent, H h)
 
void _m_walk (H h, void(*walkfn)(H, N *, void *, MwalkState *, Maddr), void *user_data)
 
void _m_detatchfn (H oh, N *on, void *data, MwalkState *s, Maddr ap)
 
H _m_detatch (H oh)
 
S_m_serialize (M *m)
 
H _m_unserialize (S *s)
 

Detailed Description

semantic tree matrix implementation

Definition in file mtree.c.

Function Documentation

void __m_add_level ( M m)
Todo:
make this not realloc each time?

Definition at line 21 of file mtree.c.

N* __m_add_nodes ( H  h,
L l,
int  c 
)
Todo:
make this not realloc each time!!

Definition at line 34 of file mtree.c.

void __m_free ( H  h,
int  free_surface 
)

free the memory used by an mtree

Parameters
[in]hhandle to mtree to free
[in]free_surfaceboolean to indicate whether to free the surface values

Definition at line 284 of file mtree.c.

N* __m_get ( H  h)

get an mtree node by handle

Parameters
[in]hthe handle to an mtree node
Returns
pointer to an N (the node)

Definition at line 264 of file mtree.c.

H __m_new ( H  parent,
Symbol  symbol,
void *  surface,
size_t  size,
uint32_t  flags 
)

Create a new tree node

Parameters
[in]parenthandle to parent node
[in]symbolsemantic symbol for the node to be create
[in]surfacepointer to node's data
[in]sizesize in bytes of the surface
[in]flags
Returns
updated handle

Definition at line 94 of file mtree.c.

H _m_add ( H  parent,
H  h 
)

add an mtree into an existing tree

Parameters
[in]parenthandle to the parent to be added to
[in]hhandle to the tree to add in
Returns
handle of newly added (sub) tree

this function is destructive in that the task is accomplished by copying the values from the tree at h, and then freeing it.

Definition at line 488 of file mtree.c.

Maddr _m_child ( H  h,
Mindex  c 
)

get matrix address of a child of a given mtree node

Parameters
[in]hhandle to the node
[in]cindex of child
Returns
Maddr of child

Definition at line 383 of file mtree.c.

int _m_children ( H  h)

return the number of children of a given mtree node

Parameters
[in]hhandle to the node
Returns
child count

Definition at line 315 of file mtree.c.

H _m_detatch ( H  oh)

detach a branch of a tree

Parameters
[in]ohhandle of mtree node to detach from the mtree
Returns
hande to newly detached tree

Definition at line 631 of file mtree.c.

H _m_new_from_t ( T t)

Create a new mtree that is a copy of a ttree

Parameters
[in]tpointer to source ttree
Returns
handle to mtree

Definition at line 206 of file mtree.c.

H _m_new_root ( Symbol  s)

Create a new tree

Parameters
[in]symbolsemantic symbol for the node to be created
Returns
handle to root node

Definition at line 134 of file mtree.c.

H _m_newi ( H  parent,
Symbol  symbol,
int  surface 
)

Create a new mtree node with an integer surface

Parameters
[in]parentparent node handle for the node to be created. Can be 0 if this is a root node
[in]symbolsemantic symbol for the node to be create
[in]surfaceinteger value to store in the surface
Returns
handle to node

Definition at line 157 of file mtree.c.

H _m_newr ( H  parent,
Symbol  s 
)

Create a new mtree node with no surface value

Parameters
[in]parentparent node handle for the node to be created. Can be 0 if this is a root node
[in]symbolsemantic symbol for the node to be create
Returns
handle to node

Definition at line 145 of file mtree.c.

Maddr _m_next_sibling ( H  h)

get matrix address of a node's next sibling

Parameters
[in]hhandle to the node
Returns
Maddr of next sibling child

Definition at line 459 of file mtree.c.

Maddr _m_parent ( H  h)

get matrix address of a mtree node's parent

Parameters
[in]hhandle to the node
Returns
Maddr of parent node

Definition at line 366 of file mtree.c.

S* _m_serialize ( M m)

create a serialized version of an mtree

Parameters
[in]ohhandle of mtree node to detach from the mtree
[in,out]sizePpointer to size_t value to return length of serialized data
Returns
pointer to newly malloced buffer of serialized tree data

Definition at line 645 of file mtree.c.

size_t _m_size ( H  h)

Get an mtree node's surface size

Parameters
[in]hhandle to the node
Returns
size

Definition at line 276 of file mtree.c.

void* _m_surface ( H  h)

get the data of a given mtree node

Parameters
[in]hhandle to the node
Returns
pointer to node's surface

Definition at line 352 of file mtree.c.

Symbol _m_symbol ( H  h)

get the symbol of a given mtree node

Parameters
[in]hhandle to the node
Returns
node's Symbol

Definition at line 448 of file mtree.c.

H _m_unserialize ( S s)

build mtree from serialized mtree data

[in] pointer to serialized data

Returns
handle to new mtree

Definition at line 743 of file mtree.c.

void _m_walk ( H  h,
void(*)(H, N *, void *, MwalkState *, Maddr walkfn,
void *  user_data 
)

walk an mtree

Parameters
[in]hmtree to walk
[in]walkfnfunction pointer to function to be executed on each node of the tree
[in]user_datadata to pass to the waklfn
Todo:
checks to make sure root isn't deleted or null?

Definition at line 524 of file mtree.c.

T* _t_new_from_m ( H  h)

Create a new ttree that is a copy of an mtree

Parameters
[in]hhandle to source mtree
Returns
handle to mtree

Definition at line 250 of file mtree.c.