Remove the now unused tommy_arrayblk

This commit is contained in:
Andrea Mazzoleni 2016-11-03 18:36:33 +01:00
parent 18f89c1a56
commit e58621dada
6 changed files with 0 additions and 245 deletions

View file

@ -54,7 +54,6 @@ noinst_HEADERS = \
raid/memory.h \
raid/test.h \
tommyds/tommyarray.h \
tommyds/tommyarrayblk.h \
tommyds/tommyarrayblkof.h \
tommyds/tommychain.h \
tommyds/tommyhash.h \
@ -63,7 +62,6 @@ noinst_HEADERS = \
tommyds/tommytree.h \
tommyds/tommytypes.h \
tommyds/tommyarray.c \
tommyds/tommyarrayblk.c \
tommyds/tommyarrayblkof.c \
tommyds/tommyhash.c \
tommyds/tommyhashdyn.c \

View file

@ -25,7 +25,6 @@
#include "tommyds/tommytree.h"
#include "tommyds/tommyhashdyn.h"
#include "tommyds/tommyarray.h"
#include "tommyds/tommyarrayblk.h"
#include "tommyds/tommyarrayblkof.h"
/****************************************************************************/

View file

@ -29,7 +29,6 @@
#include "support.h"
#include "tommyds/tommyhash.h"
#include "tommyds/tommyarray.h"
#include "tommyds/tommyarrayblk.h"
#include "tommyds/tommyarrayblkof.h"
#include "tommyds/tommyhashdyn.h"
@ -344,7 +343,6 @@ static void tommy_test_foreach_arg(void* void_arg, void* obj)
static void test_tommy(void)
{
tommy_array array;
tommy_arrayblk arrayblk;
tommy_arrayblkof arrayblkof;
tommy_list list;
tommy_hashdyn hashdyn;
@ -353,12 +351,10 @@ static void test_tommy(void)
unsigned i;
tommy_array_init(&array);
tommy_arrayblk_init(&arrayblk);
tommy_arrayblkof_init(&arrayblkof, sizeof(unsigned));
for (i = 0; i < TOMMY_SIZE; ++i) {
tommy_array_insert(&array, &node[i]);
tommy_arrayblk_insert(&arrayblk, &node[i]);
tommy_arrayblkof_grow(&arrayblkof, i + 1);
*(unsigned*)tommy_arrayblkof_ref(&arrayblkof, i) = i;
}
@ -368,11 +364,6 @@ static void test_tommy(void)
goto bail;
/* LCOV_EXCL_STOP */
}
if (tommy_arrayblk_memory_usage(&arrayblk) < TOMMY_SIZE * sizeof(void*)) {
/* LCOV_EXCL_START */
goto bail;
/* LCOV_EXCL_STOP */
}
if (tommy_arrayblkof_memory_usage(&arrayblkof) < TOMMY_SIZE * sizeof(unsigned)) {
/* LCOV_EXCL_START */
goto bail;
@ -385,11 +376,6 @@ static void test_tommy(void)
goto bail;
/* LCOV_EXCL_STOP */
}
if (tommy_arrayblk_get(&arrayblk, i) != &node[i]) {
/* LCOV_EXCL_START */
goto bail;
/* LCOV_EXCL_STOP */
}
if (*(unsigned*)tommy_arrayblkof_ref(&arrayblkof, i) != i) {
/* LCOV_EXCL_START */
goto bail;
@ -398,7 +384,6 @@ static void test_tommy(void)
}
tommy_arrayblkof_done(&arrayblkof);
tommy_arrayblk_done(&arrayblk);
tommy_array_done(&array);
tommy_list_init(&list);

View file

@ -35,7 +35,6 @@
#include "tommyhash.c"
#include "tommyarray.c"
#include "tommyarrayblk.c"
#include "tommyarrayblkof.c"
#include "tommylist.c"
#include "tommytree.c"

View file

@ -1,82 +0,0 @@
/*
* Copyright (c) 2013, Andrea Mazzoleni. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
#include "tommyarrayblk.h"
/******************************************************************************/
/* array */
void tommy_arrayblk_init(tommy_arrayblk* array)
{
tommy_array_init(&array->block);
array->count = 0;
}
void tommy_arrayblk_done(tommy_arrayblk* array)
{
tommy_count_t i;
for (i = 0; i < tommy_array_size(&array->block); ++i)
tommy_free(tommy_array_get(&array->block, i));
tommy_array_done(&array->block);
}
void tommy_arrayblk_grow(tommy_arrayblk* array, tommy_count_t count)
{
tommy_count_t block_max;
tommy_count_t block_mac;
if (array->count >= count)
return;
array->count = count;
block_max = (count + TOMMY_ARRAYBLK_SIZE - 1) / TOMMY_ARRAYBLK_SIZE;
block_mac = tommy_array_size(&array->block);
if (block_mac < block_max) {
/* grow the block array */
tommy_array_grow(&array->block, block_max);
/* allocate new blocks */
while (block_mac < block_max) {
void** ptr = tommy_cast(void**, tommy_calloc(TOMMY_ARRAYBLK_SIZE, sizeof(void*)));
/* set the new block */
tommy_array_set(&array->block, block_mac, ptr);
++block_mac;
}
}
}
tommy_size_t tommy_arrayblk_memory_usage(tommy_arrayblk* array)
{
return tommy_array_memory_usage(&array->block) + tommy_array_size(&array->block) * TOMMY_ARRAYBLK_SIZE * sizeof(void*);
}

View file

@ -1,144 +0,0 @@
/*
* Copyright (c) 2013, Andrea Mazzoleni. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
/** \file
* Dynamic array based on blocks of fixed size.
*
* This array is able to grow dynamically upon request, without any reallocation.
*
* The grow operation involves an allocation of a new array block, without reallocating
* the already used memory, and then not increasing the heap fragmentation,
* and minimize the space occupation.
* This also implies that the address of the stored elements never change.
*
* Allocated blocks are always of the same fixed size of 4 Ki pointers.
*/
#ifndef __TOMMYARRAYBLK_H
#define __TOMMYARRAYBLK_H
#include "tommytypes.h"
#include "tommyarray.h"
#include <assert.h> /* for assert */
/******************************************************************************/
/* array */
/**
* Elements for each block.
*/
#define TOMMY_ARRAYBLK_SIZE (4 * 1024)
/**
* Array container type.
* \note Don't use internal fields directly, but access the container only using functions.
*/
typedef struct tommy_arrayblk_struct {
tommy_array block; /**< Array of blocks. */
tommy_count_t count; /**< Number of initialized elements in the array. */
} tommy_arrayblk;
/**
* Initializes the array.
*/
void tommy_arrayblk_init(tommy_arrayblk* array);
/**
* Deinitializes the array.
*/
void tommy_arrayblk_done(tommy_arrayblk* array);
/**
* Grows the size up to the specified value.
* All the new elements in the array are initialized with the 0 value.
*/
void tommy_arrayblk_grow(tommy_arrayblk* array, tommy_count_t size);
/**
* Gets a reference of the element at the specified position.
* You must be sure that space for this position is already
* allocated calling tommy_arrayblk_grow().
*/
tommy_inline void** tommy_arrayblk_ref(tommy_arrayblk* array, tommy_count_t pos)
{
void** ptr;
assert(pos < array->count);
ptr = tommy_cast(void**, tommy_array_get(&array->block, pos / TOMMY_ARRAYBLK_SIZE));
return &ptr[pos % TOMMY_ARRAYBLK_SIZE];
}
/**
* Sets the element at the specified position.
* You must be sure that space for this position is already
* allocated calling tommy_arrayblk_grow().
*/
tommy_inline void tommy_arrayblk_set(tommy_arrayblk* array, tommy_count_t pos, void* element)
{
*tommy_arrayblk_ref(array, pos) = element;
}
/**
* Gets the element at the specified position.
* You must be sure that space for this position is already
* allocated calling tommy_arrayblk_grow().
*/
tommy_inline void* tommy_arrayblk_get(tommy_arrayblk* array, tommy_count_t pos)
{
return *tommy_arrayblk_ref(array, pos);
}
/**
* Grows and inserts a new element at the end of the array.
*/
tommy_inline void tommy_arrayblk_insert(tommy_arrayblk* array, void* element)
{
tommy_count_t pos = array->count;
tommy_arrayblk_grow(array, pos + 1);
tommy_arrayblk_set(array, pos, element);
}
/**
* Gets the initialized size of the array.
*/
tommy_inline tommy_count_t tommy_arrayblk_size(tommy_arrayblk* array)
{
return array->count;
}
/**
* Gets the size of allocated memory.
*/
tommy_size_t tommy_arrayblk_memory_usage(tommy_arrayblk* array);
#endif