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

semantic tree matrix header file `` More...

#include <string.h>
#include <stdlib.h>
#include "ceptr_error.h"
#include "sys_defs.h"
#include "ceptr_types.h"
Include dependency graph for mtree.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  MwalkState
 
#define _m_new(parent, symbol, surface, size)   __m_new(parent,symbol,surface,size,0)
 
#define _m_newt(parent, symbol, h)   __m_new(parent,symbol,&(h),sizeof(H),TFLAG_SURFACE_IS_TREE)
 
#define _m_free(h)   __m_free(h,1)
 
#define maddreq(x, y)   ((x).i == (y).i && (x).l == (y).l)
 
#define DO_KIDSM(h, x)   {int i,_c=_m_children(h);for(i=1;i<=_c;i++){x;}}
 
#define _GET_LEVEL(h, l)   (&(h).m->lP[l])
 
#define _GET_NODE(h, l, i)   (&(l)->nP[i])
 
#define GET_LEVEL(h)   _GET_LEVEL(h,(h).a.l)
 
#define GET_NODE(h, l)   _GET_NODE(h,l,(h).a.i)
 
#define spec_is_maddr_equal(got, expected)   spec_total++; if (maddreq(expected,got)){putchar('.');} else {putchar('F');sprintf(failures[spec_failures++],"%s:%d expected %s to be %d.%d but was %d.%d",__FUNCTION__,__LINE__,#got,expected.l,expected.i,got.l,got.i);}
 
typedef struct MwalkState MwalkState
 
const H null_H
 
H __m_new (H parent, Symbol symbol, void *surface, size_t size, uint32_t flags)
 
H _m_newi (H h, Symbol symbol, int surface)
 
H _m_new_from_t (T *t)
 
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 i)
 
Symbol _m_symbol (H h)
 
Maddr _m_next_sibling (H h)
 
H _m_new_root (Symbol s)
 
H _m_newr (H parent, Symbol s)
 
H _m_add (H parent, H h)
 
H _m_detatch (H h)
 
S_m_serialize (M *m)
 
H _m_unserialize (S *)
 
void _m_walk (H h, void(*walkfn)(H, N *, void *, MwalkState *, Maddr), void *user_data)
 

Detailed Description

semantic tree matrix header file ``

Definition in file mtree.h.

Function Documentation

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.