BlockArray impl

Implements BlockArray.

Summary
BlockArray implImplements BlockArray.
CopyrightThis program is free software.
Files
C-kern/api/ds/inmem/blockarray.hHeader file BlockArray.
C-kern/ds/inmem/blockarray.cImplementation file BlockArray impl.
Types
struct datablock_tExport datablock_t into global namespace.
struct ptrblock_tExport ptrblock_t into global namespace.
Function
helper
datablock_tA memory block which contains the array elements.
lifetime
ptrblock_tA memory block which contains pointers to other ptrblock_t or datablock_t.
lifetime
blockarray_t
static variables
lifetime
query
update
adaptdepth_blockarrayAdds a new root ptrblock_t and sets <ptrblock_t.childs[0]> to old root.
test
build_test_nodeAllocates a tree with pow(2, depth+1)-1 nodes.
build_test_treeCalls build_test_node to build the test tree.

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

© 2013 Jörg Seebohn

Files

C-kern/api/ds/inmem/blockarray.h

Header file BlockArray.

C-kern/ds/inmem/blockarray.c

Implementation file BlockArray impl.

Types

struct datablock_t

typedef struct datablock_t datablock_t

Export datablock_t into global namespace.

struct ptrblock_t

typedef struct ptrblock_t ptrblock_t

Export ptrblock_t into global namespace.

Function

Summary

helper

datablock_t

struct datablock_t

A memory block which contains the array elements.

Summary

lifetime

ptrblock_t

struct ptrblock_t

A memory block which contains pointers to other ptrblock_t or datablock_t.  The current implementation supports only one memory block size which is the same for datablock_t and ptrblock_t.

Summary

lifetime

blockarray_t

Summary
static variables
lifetime
query
update
adaptdepth_blockarrayAdds a new root ptrblock_t and sets <ptrblock_t.childs[0]> to old root.
test
build_test_nodeAllocates a tree with pow(2, depth+1)-1 nodes.
build_test_treeCalls build_test_node to build the test tree.

static variables

lifetime

query

update

adaptdepth_blockarray

static int adaptdepth_blockarray(blockarray_t *barray,
uint8_t depth)

Adds a new root ptrblock_t and sets <ptrblock_t.childs[0]> to old root.  This step is repeated until barray->depth >= depth.  There is always added at least one new root even if depth is <= barray->depth.

(unchecked) Precondition

  • depth > barray->depth

test

build_test_node

static int build_test_node(void **block,
pagesize_e pgsize,
uint8_t depth)

Allocates a tree with pow(2, depth+1)-1 nodes.  All nodes at a depth > 0 are allocated as ptrblock_t and all nodes at depth == 0 are allocated as datablock_t.  A ptrblock_t contains two childs at index 0 and maxindex.

build_test_tree

static int build_test_tree(blockarray_t *barray,
pagesize_e pgsize,
uint8_t depth)

Calls build_test_node to build the test tree.  The old root is expected at depth 0 and it is deallocated and replaced by the new root returned from build_test_node.  The depth is changed.

A blocked array implements an array where not all contained elements are stored in a contiguous way.
Implements BlockArray.
typedef struct datablock_t datablock_t
Export datablock_t into global namespace.
struct datablock_t
A memory block which contains the array elements.
typedef struct ptrblock_t ptrblock_t
Export ptrblock_t into global namespace.
struct ptrblock_t
A memory block which contains pointers to other ptrblock_t or datablock_t.
static int adaptdepth_blockarray(blockarray_t *barray,
uint8_t depth)
Adds a new root ptrblock_t and sets ptrblock_t.childs[0] to old root.
static int build_test_node(void **block,
pagesize_e pgsize,
uint8_t depth)
Allocates a tree with pow(2, depth+1)-1 nodes.
static int build_test_tree(blockarray_t *barray,
pagesize_e pgsize,
uint8_t depth)
Calls build_test_node to build the test tree.
Close