ArraySF-Node

Defines node type arraysf_node_t which can be stored in an array of type arraysf_t.  Defines also the internal node type arraysf_mwaybranch_t which is used in the implementation of arraysf_t.

Summary
ArraySF-NodeDefines node type arraysf_node_t which can be stored in an array of type arraysf_t.
CopyrightThis program is free software.
Files
C-kern/api/ds/inmem/node/arraysf_node.hHeader file ArraySF-Node.
Types
struct arraysf_node_tExport arraysf_node_t.
struct arraysf_mwaybranch_tExport arraysf_mwaybranch_t.
struct arraysf_unode_tExport arraysf_unode_t.
arraysf_node_tGeneric node type stored by arraysf_t.
posIndex of node stored in arraysf_t.
lifetime
arraysf_node_INITStatic initializer with parameter pos of type size_t.
generic
arraysf_node_EMBEDAllows to embed members of arraysf_node_t into another structure.
arraysf_mwaybranch_tInternal node to implement a multiway trie.
childA 4-way array of child nodes.
shiftPosition of bit in array index used to branch.
usedThe number of entries in child which are not 0.
lifetime
init_arraysfmwaybranchInitializes a new branch node.
query
childindex_arraysfmwaybranchDetermines the index into the internal array arraysf_mwaybranch_t.childs.
change
setchild_arraysfmwaybranchChanges entries in arry arraysf_mwaybranch_t.child.
query
branch_arraysfunodeGets pointer to value arraysf_mwaybranch_t.
node_arraysfunodeGets pointer to value arraysf_node_t.
isbranchtype_arraysfunodeReturns true in case node is pointer to arraysf_mwaybranch_t.
conversion
nodecast_arraysfunodeCasts pointer to arraysf_node_t into pointer to arraysf_unode_t.
branchcast_arraysfunodeCasts pointer to arraysf_mwaybranch_t into pointer to arraysf_unode_t.
inline implementation
arraysf_mwaybranch_t
childindex_arraysfmwaybranchImplements arraysf_mwaybranch_t.childindex_arraysfmwaybranch.
init_arraysfmwaybranchImplements arraysf_mwaybranch_t.init_arraysfmwaybranch.
setchild_arraysfmwaybranchImplements arraysf_mwaybranch_t.setchild_arraysfmwaybranch.
arraysf_unode_t
branch_arraysfunodeImplements <arraysf_unode_t.branch_arraysfunode>.
isbranchtype_arraysfunodeImplements <arraysf_unode_t.isbranchtype_arraysfunode>.
node_arraysfunodeImplements <arraysf_unode_t.node_arraysfunode>.
nodecast_arraysfunodeImplements <arraysf_unode_t.nodecast_arraysfunode>.

Copyright

This program is free software.  You can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more details.

Author

© 2011 Jörg Seebohn

Files

C-kern/api/ds/inmem/node/arraysf_node.h

Header file ArraySF-Node.

Types

struct arraysf_node_t

typedef struct arraysf_node_t arraysf_node_t

Export arraysf_node_t.  User supplied (external) type.

struct arraysf_mwaybranch_t

typedef struct arraysf_mwaybranch_t arraysf_mwaybranch_t

Export arraysf_mwaybranch_t.  Internal node type.

struct arraysf_unode_t

Export arraysf_unode_t.  Either internal or external type.

arraysf_node_t

struct arraysf_node_t

Generic node type stored by arraysf_t.

Summary
posIndex of node stored in arraysf_t.
lifetime
arraysf_node_INITStatic initializer with parameter pos of type size_t.
generic
arraysf_node_EMBEDAllows to embed members of arraysf_node_t into another structure.

pos

size_t pos

Index of node stored in arraysf_t.

lifetime

arraysf_node_INIT

#define arraysf_node_INIT(pos) { pos }

Static initializer with parameter pos of type size_t.

generic

arraysf_node_EMBED

#define arraysf_node_EMBED(name_pos) size_t name_pos

Allows to embed members of arraysf_node_t into another structure.

Parameter

name_posThe name of the embedded arraysf_node_t.pos member.

Your object must inherit or embed arraysf_node_t to be manageable by arraysf_t.  With macro arraysf_node_EMBED you can do

struct object_t {
   ... ;
   // declares: size_t   arrayindex ;
   arraysf_node_EMBED(arrayindex)
}

// instead of
struct object_t {
   ... ;
   arraysf_node_t arraysfnode ;
}

arraysf_mwaybranch_t

struct arraysf_mwaybranch_t

Internal node to implement a multiway trie.  Currently this node type supports only a 4-way tree.

Summary
childA 4-way array of child nodes.
shiftPosition of bit in array index used to branch.
usedThe number of entries in child which are not 0.
lifetime
init_arraysfmwaybranchInitializes a new branch node.
query
childindex_arraysfmwaybranchDetermines the index into the internal array arraysf_mwaybranch_t.childs.
change
setchild_arraysfmwaybranchChanges entries in arry arraysf_mwaybranch_t.child.
query
branch_arraysfunodeGets pointer to value arraysf_mwaybranch_t.
node_arraysfunodeGets pointer to value arraysf_node_t.
isbranchtype_arraysfunodeReturns true in case node is pointer to arraysf_mwaybranch_t.
conversion
nodecast_arraysfunodeCasts pointer to arraysf_node_t into pointer to arraysf_unode_t.
branchcast_arraysfunodeCasts pointer to arraysf_mwaybranch_t into pointer to arraysf_unode_t.

child

arraysf_unode_t * child[4]

A 4-way array of child nodes.

shift

uint8_t shift

Position of bit in array index used to branch.  The two bits at position shift and shift+1 are used as index into array child.  To get the correct child pointer use the following formula

size_t               pos ;        // array index
arraysf_mwaybranch_t * branch ;   // current branch node
branch->child[(pos >> branch->shift) & 0x03]

used

uint8_t used

The number of entries in child which are not 0.

lifetime

init_arraysfmwaybranch

void init_arraysfmwaybranch(/*out*/arraysf_mwaybranch_t *branch,
unsigned shift,
size_t pos1,
arraysf_unode_t *childnode1,
size_t pos2,
arraysf_unode_t *childnode2)

Initializes a new branch node.  A branch node must point to at least two child nodes.  This is the reason two pointers and their corresponding index key has to be provided as parameter.

query

childindex_arraysfmwaybranch

unsigned childindex_arraysfmwaybranch(arraysf_mwaybranch_t *branch,
size_t pos)

Determines the index into the internal array arraysf_mwaybranch_t.childs.  The index is calculated from parameter pos which is the index of the node.

change

setchild_arraysfmwaybranch

void setchild_arraysfmwaybranch(arraysf_mwaybranch_t *branch,
unsigned childindex,
arraysf_node_t *childnode)

Changes entries in arry arraysf_mwaybranch_t.child.

query

branch_arraysfunode

arraysf_mwaybranch_t * branch_arraysfunode(arraysf_unode_t *node)

Gets pointer to value arraysf_mwaybranch_t.

node_arraysfunode

arraysf_node_t * node_arraysfunode(arraysf_unode_t *node)

Gets pointer to value arraysf_node_t.

isbranchtype_arraysfunode

int isbranchtype_arraysfunode(const arraysf_unode_t *node)

Returns true in case node is pointer to arraysf_mwaybranch_t.

conversion

nodecast_arraysfunode

static inline arraysf_unode_t * nodecast_arraysfunode(arraysf_node_t *node)

Casts pointer to arraysf_node_t into pointer to arraysf_unode_t.  You need to call this function to make isbranchtype_arraysfunode working properly.

branchcast_arraysfunode

static inline arraysf_unode_t * branchcast_arraysfunode(
   arraysf_mwaybranch_t *branch
)

Casts pointer to arraysf_mwaybranch_t into pointer to arraysf_unode_t.  You need to call this function to make isbranchtype_arraysfunode working properly.

inline implementation

Summary
arraysf_mwaybranch_t
childindex_arraysfmwaybranchImplements arraysf_mwaybranch_t.childindex_arraysfmwaybranch.
init_arraysfmwaybranchImplements arraysf_mwaybranch_t.init_arraysfmwaybranch.
setchild_arraysfmwaybranchImplements arraysf_mwaybranch_t.setchild_arraysfmwaybranch.
arraysf_unode_t
branch_arraysfunodeImplements <arraysf_unode_t.branch_arraysfunode>.
isbranchtype_arraysfunodeImplements <arraysf_unode_t.isbranchtype_arraysfunode>.
node_arraysfunodeImplements <arraysf_unode_t.node_arraysfunode>.
nodecast_arraysfunodeImplements <arraysf_unode_t.nodecast_arraysfunode>.

arraysf_mwaybranch_t

childindex_arraysfmwaybranch

#define childindex_arraysfmwaybranch(
   branch,
   pos
) (0x03u & ((pos) >> (branch)->shift))

Implements arraysf_mwaybranch_t.childindex_arraysfmwaybranch.

init_arraysfmwaybranch

#define init_arraysfmwaybranch(
   branch,
   _shift,
   pos1,
   childnode1,
   pos2,
   childnode2
) do { memset((branch)->child, 0, sizeof((branch)->child)) ; (branch)->child[0x03u & ((pos1) >> (_shift))] = childnode1 ; (branch)->child[0x03u & ((pos2) >> (_shift))] = childnode2 ; (branch)->shift = (uint8_t) _shift ; (branch)->used = 2 ; } while(0)

Implements arraysf_mwaybranch_t.init_arraysfmwaybranch.

setchild_arraysfmwaybranch

#define setchild_arraysfmwaybranch(
   branch,
   childindex,
   childnode
) do { (branch)->child[childindex] = (childnode) ; } while(0)

Implements arraysf_mwaybranch_t.setchild_arraysfmwaybranch.

arraysf_unode_t

branch_arraysfunode

#define branch_arraysfunode(
   node
) ( __extension__ ({ arraysf_unode_t * _node1 = (node) ; (arraysf_mwaybranch_t*)(0x01 ^ (uintptr_t)(_node1)) ; }))

Implements <arraysf_unode_t.branch_arraysfunode>.

isbranchtype_arraysfunode

#define isbranchtype_arraysfunode(
   node
) ( __extension__ ({ const arraysf_unode_t * _node2 = (node) ; ((uintptr_t)(_node2) & 0x01) ; }))

Implements <arraysf_unode_t.isbranchtype_arraysfunode>.

node_arraysfunode

#define node_arraysfunode(
   node
) ( __extension__ ({ arraysf_unode_t * _node3 = (node) ; (arraysf_node_t*) _node3 ; }))

Implements <arraysf_unode_t.node_arraysfunode>.

nodecast_arraysfunode

static inline arraysf_unode_t * nodecast_arraysfunode(arraysf_node_t *node)

Implements <arraysf_unode_t.nodecast_arraysfunode>.

struct arraysf_node_t
Generic node type stored by arraysf_t.
Defines node type arraysf_node_t which can be stored in an array of type arraysf_t.
typedef struct arraysf_node_t arraysf_node_t
Export arraysf_node_t.
typedef struct arraysf_mwaybranch_t arraysf_mwaybranch_t
Export arraysf_mwaybranch_t.
struct arraysf_mwaybranch_t
Internal node to implement a multiway trie.
size_t pos
Index of node stored in arraysf_t.
#define arraysf_node_INIT(pos) { pos }
Static initializer with parameter pos of type size_t.
#define arraysf_node_EMBED(name_pos) size_t name_pos
Allows to embed members of arraysf_node_t into another structure.
arraysf_unode_t * child[4]
A 4-way array of child nodes.
uint8_t shift
Position of bit in array index used to branch.
uint8_t used
The number of entries in child which are not 0.
void init_arraysfmwaybranch(/*out*/arraysf_mwaybranch_t *branch,
unsigned shift,
size_t pos1,
arraysf_unode_t *childnode1,
size_t pos2,
arraysf_unode_t *childnode2)
Initializes a new branch node.
unsigned childindex_arraysfmwaybranch(arraysf_mwaybranch_t *branch,
size_t pos)
Determines the index into the internal array arraysf_mwaybranch_t.childs.
void setchild_arraysfmwaybranch(arraysf_mwaybranch_t *branch,
unsigned childindex,
arraysf_node_t *childnode)
Changes entries in arry arraysf_mwaybranch_t.child.
arraysf_mwaybranch_t * branch_arraysfunode(arraysf_unode_t *node)
Gets pointer to value arraysf_mwaybranch_t.
arraysf_node_t * node_arraysfunode(arraysf_unode_t *node)
Gets pointer to value arraysf_node_t.
int isbranchtype_arraysfunode(const arraysf_unode_t *node)
Returns true in case node is pointer to arraysf_mwaybranch_t.
static inline arraysf_unode_t * nodecast_arraysfunode(arraysf_node_t *node)
Casts pointer to arraysf_node_t into pointer to arraysf_unode_t.
static inline arraysf_unode_t * branchcast_arraysfunode(
   arraysf_mwaybranch_t *branch
)
Casts pointer to arraysf_mwaybranch_t into pointer to arraysf_unode_t.
#define childindex_arraysfmwaybranch(
   branch,
   pos
) (0x03u & ((pos) >> (branch)->shift))
Implements arraysf_mwaybranch_t.childindex_arraysfmwaybranch.
#define init_arraysfmwaybranch(
   branch,
   _shift,
   pos1,
   childnode1,
   pos2,
   childnode2
) do { memset((branch)->child, 0, sizeof((branch)->child)) ; (branch)->child[0x03u & ((pos1) >> (_shift))] = childnode1 ; (branch)->child[0x03u & ((pos2) >> (_shift))] = childnode2 ; (branch)->shift = (uint8_t) _shift ; (branch)->used = 2 ; } while(0)
Implements arraysf_mwaybranch_t.init_arraysfmwaybranch.
#define setchild_arraysfmwaybranch(
   branch,
   childindex,
   childnode
) do { (branch)->child[childindex] = (childnode) ; } while(0)
Implements arraysf_mwaybranch_t.setchild_arraysfmwaybranch.
#define branch_arraysfunode(
   node
) ( __extension__ ({ arraysf_unode_t * _node1 = (node) ; (arraysf_mwaybranch_t*)(0x01 ^ (uintptr_t)(_node1)) ; }))
Implements arraysf_unode_t.branch_arraysfunode.
#define isbranchtype_arraysfunode(
   node
) ( __extension__ ({ const arraysf_unode_t * _node2 = (node) ; ((uintptr_t)(_node2) & 0x01) ; }))
Implements arraysf_unode_t.isbranchtype_arraysfunode.
#define node_arraysfunode(
   node
) ( __extension__ ({ arraysf_unode_t * _node3 = (node) ; (arraysf_node_t*) _node3 ; }))
Implements arraysf_unode_t.node_arraysfunode.
static inline arraysf_unode_t * nodecast_arraysfunode(arraysf_node_t *node)
Implements arraysf_unode_t.nodecast_arraysfunode.
Close