summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--clib/Rules.mk1
-rw-r--r--clib/cunit/vector.c176
-rw-r--r--clib/cunit/vector.h26
-rw-r--r--clib/src/tree_iter.c1
-rw-r--r--clib/src/vector.c669
-rw-r--r--clib/src/vector_iter.c184
-rw-r--r--clib/test/vector.c90
-rw-r--r--clib/vector.h439
-rw-r--r--clib/vector_iter.h188
9 files changed, 0 insertions, 1774 deletions
diff --git a/clib/Rules.mk b/clib/Rules.mk
index b04180e..e115e60 100644
--- a/clib/Rules.mk
+++ b/clib/Rules.mk
@@ -33,7 +33,6 @@ OBJS = err.o crc32.o misc.o ecc.o \
exception.o slab.o \
list.o list_iter.o \
tree.o tree_iter.o \
- vector.o vector_iter.o \
value.o mq.o \
memory_leak_detection.o \
trace_indent.o checksum.o
diff --git a/clib/cunit/vector.c b/clib/cunit/vector.c
deleted file mode 100644
index cd0f34c..0000000
--- a/clib/cunit/vector.c
+++ /dev/null
@@ -1,176 +0,0 @@
-/* IBM_PROLOG_BEGIN_TAG */
-/* This is an automatically generated prolog. */
-/* */
-/* $Source: clib/cunit/vector.c $ */
-/* */
-/* OpenPOWER FFS Project */
-/* */
-/* Contributors Listed Below - COPYRIGHT 2014,2015 */
-/* [+] International Business Machines Corp. */
-/* */
-/* */
-/* Licensed under the Apache License, Version 2.0 (the "License"); */
-/* you may not use this file except in compliance with the License. */
-/* You may obtain a copy of the License at */
-/* */
-/* http://www.apache.org/licenses/LICENSE-2.0 */
-/* */
-/* Unless required by applicable law or agreed to in writing, software */
-/* distributed under the License is distributed on an "AS IS" BASIS, */
-/* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or */
-/* implied. See the License for the specific language governing */
-/* permissions and limitations under the License. */
-/* */
-/* IBM_PROLOG_END_TAG */
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-
-#include <clib/libclib.h>
-
-#include <clib/crc32.h>
-#include <clib/vector.h>
-
-#include <CUnit/Basic.h>
-
-#define COUNT 10000
-#define SEED 41
-
-static int init_vector(void) {
- return 0;
-}
-
-static int clean_vector(void) {
- return 0;
-}
-
-static void vector_1(void) {
- vector_t v;
-
- CU_ASSERT(vector_init(&v, "my_vector", 0) == -1)
- err_t * err = err_get();
- fprintf(stderr, "%s(%d): %.*s\n",
- err_file(err), err_line(err), err_size(err),
- (const char *)err_data(err));
-
- for (size_t i=VECTOR_ELEM_MIN; i<=VECTOR_ELEM_MAX; i++) {
- CU_ASSERT(vector_init(&v, "my_vector", i) == 0);
-
- CU_ASSERT(vector_size(&v) == 0);
- CU_ASSERT(vector_pages(&v) == 0);
- CU_ASSERT(vector_capacity(&v) == 0);
- CU_ASSERT(vector_elem_size(&v) == i);
- CU_ASSERT(vector_elem_size(&v) * v.hdr.elem_num <= v.hdr.page_size);
-
- CU_ASSERT(vector_delete(&v) == 0);
- }
-}
-
-uint32_t crc2;
-
-static void vector_2(void) {
- vector_t v;
-
- CU_ASSERT(vector_init(&v, "my_vector.bin", 1) == 0);
- CU_ASSERT(vector_size(&v) == 0);
- CU_ASSERT(vector_pages(&v) == 0);
- CU_ASSERT(vector_capacity(&v) == 0);
- CU_ASSERT(vector_elem_size(&v) == 1);
-
- CU_ASSERT(vector_size(&v, COUNT) == COUNT);
- CU_ASSERT(COUNT <= vector_capacity(&v));
- CU_ASSERT(COUNT <= vector_size(&v));
- CU_ASSERT(3 <= vector_pages(&v));
-
- for (int i=0; i<COUNT; i++) {
- unsigned char c = (unsigned char)i;
- crc2 = clib_crc32(c, crc2);
- CU_ASSERT(vector_put(&v, i, &c) == 0);
- }
- CU_ASSERT_FATAL(crc2 != 0);
-
- FILE * f = fopen(v.hdr.name, "w");
- CU_ASSERT_FATAL(f != NULL);
- CU_ASSERT(COUNT < vector_save(&v, f));
- fclose(f), f = NULL;
-
- CU_ASSERT(vector_delete(&v) == 0);
-}
-
-uint32_t crc3;
-
-static void vector_3(void) {
- vector_t v;
- vector_init(&v, __func__, 1);
-
- CU_ASSERT(vector_size(&v) == 0);
- CU_ASSERT(vector_pages(&v) == 0);
- CU_ASSERT(vector_capacity(&v) == 0);
- CU_ASSERT(vector_elem_size(&v) == 1);
-
- FILE * f = fopen("my_vector.bin", "r");
- CU_ASSERT_FATAL(f != NULL);
- CU_ASSERT(COUNT < vector_load(&v, f));
- fclose(f), f = NULL;
-
- crc3 = 0;
-
- for (int i=0; i<COUNT; i++) {
- unsigned char c;
- vector_get(&v, i, &c);
- crc3 = clib_crc32(c, crc3);
- }
- CU_ASSERT_FATAL(crc3 != 0);
-
- CU_ASSERT_FATAL(crc2 == crc3);
-
- vector_delete(&v);
-}
-
-static void vector_4(void) {
- vector_t v;
-
- if (vector_init(&v, NULL, 0) < 0) {
- err_t * err = err_get();
- fprintf(stderr, "%s(%d): UNEXPECTED: %.*s\n",
- err_file(err), err_line(err), err_size(err),
- (const char *)err_data(err));
- }
-
- if (vector_init(&v, "my_vector", 0) < 0) {
- err_t * err = err_get();
- fprintf(stderr, "%s(%d): UNEXPECTED: %.*s\n",
- err_file(err), err_line(err), err_size(err),
- (const char *)err_data(err));
- }
-
- for (size_t i=VECTOR_ELEM_MIN; i<=VECTOR_ELEM_MAX; i+=3) {
- vector_init(&v, "my_vector", i);
-
- CU_ASSERT(vector_size(&v) == 0);
- CU_ASSERT(vector_pages(&v) == 0);
- CU_ASSERT(vector_capacity(&v) == 0);
- CU_ASSERT(vector_elem_size(&v) == i);
- CU_ASSERT(vector_elem_size(&v) * v.hdr.elem_num <= v.hdr.page_size);
-
- vector_size(&v, COUNT);
-
- CU_ASSERT(vector_size(&v) == COUNT);
- CU_ASSERT(vector_size(&v) <= vector_capacity(&v));
- CU_ASSERT(0 < vector_pages(&v));
-
- vector_delete(&v);
- }
-}
-
-void vector_test(void) {
- CU_pSuite suite = CU_add_suite("vector", init_vector, clean_vector);
- if (NULL == suite)
- return;
-
- if (CU_add_test(suite, "vector_1: vector_init()", vector_1) == NULL) return;
- if (CU_add_test(suite, "vector_2: vector_save()", vector_2) == NULL) return;
- if (CU_add_test(suite, "vector_3: vector_load()", vector_3) == NULL) return;
- if (CU_add_test(suite, "vector_4: vector_size()", vector_4) == NULL) return;
-}
diff --git a/clib/cunit/vector.h b/clib/cunit/vector.h
deleted file mode 100644
index 91dfd4e..0000000
--- a/clib/cunit/vector.h
+++ /dev/null
@@ -1,26 +0,0 @@
-/* IBM_PROLOG_BEGIN_TAG */
-/* This is an automatically generated prolog. */
-/* */
-/* $Source: clib/cunit/vector.h $ */
-/* */
-/* OpenPOWER FFS Project */
-/* */
-/* Contributors Listed Below - COPYRIGHT 2014,2015 */
-/* [+] International Business Machines Corp. */
-/* */
-/* */
-/* Licensed under the Apache License, Version 2.0 (the "License"); */
-/* you may not use this file except in compliance with the License. */
-/* You may obtain a copy of the License at */
-/* */
-/* http://www.apache.org/licenses/LICENSE-2.0 */
-/* */
-/* Unless required by applicable law or agreed to in writing, software */
-/* distributed under the License is distributed on an "AS IS" BASIS, */
-/* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or */
-/* implied. See the License for the specific language governing */
-/* permissions and limitations under the License. */
-/* */
-/* IBM_PROLOG_END_TAG */
-
-void vector_test(void);
diff --git a/clib/src/tree_iter.c b/clib/src/tree_iter.c
index f94fe0e..2e1993d 100644
--- a/clib/src/tree_iter.c
+++ b/clib/src/tree_iter.c
@@ -42,7 +42,6 @@
#include <limits.h>
#include "libclib.h"
-#include "vector.h"
#include "tree_iter.h"
/* ======================================================================= */
diff --git a/clib/src/vector.c b/clib/src/vector.c
deleted file mode 100644
index 73aa5c4..0000000
--- a/clib/src/vector.c
+++ /dev/null
@@ -1,669 +0,0 @@
-/* IBM_PROLOG_BEGIN_TAG */
-/* This is an automatically generated prolog. */
-/* */
-/* $Source: clib/src/vector.c $ */
-/* */
-/* OpenPOWER FFS Project */
-/* */
-/* Contributors Listed Below - COPYRIGHT 2014,2015 */
-/* [+] International Business Machines Corp. */
-/* */
-/* */
-/* Licensed under the Apache License, Version 2.0 (the "License"); */
-/* you may not use this file except in compliance with the License. */
-/* You may obtain a copy of the License at */
-/* */
-/* http://www.apache.org/licenses/LICENSE-2.0 */
-/* */
-/* Unless required by applicable law or agreed to in writing, software */
-/* distributed under the License is distributed on an "AS IS" BASIS, */
-/* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or */
-/* implied. See the License for the specific language governing */
-/* permissions and limitations under the License. */
-/* */
-/* IBM_PROLOG_END_TAG */
-
-/*
- * File: vector.c
- * Author: Shaun Wetzstein <shaun@us.ibm.com>
- * Descr: dynamic vector
- * Note:
- * Date: 08/29/10
- */
-
-#include <unistd.h>
-#include <stdarg.h>
-#include <stdlib.h>
-#include <malloc.h>
-#include <stdint.h>
-#include <stdio.h>
-#include <string.h>
-#include <errno.h>
-#include <limits.h>
-
-#include "libclib.h"
-
-#include "vector.h"
-#include "tree.h"
-#include "tree_iter.h"
-#include "mq.h"
-
-/* ======================================================================= */
-
-/*! @cond */
-#define VECTOR_NODE_MAGIC "VCND"
-
-#define VECTOR_NODE_MAGIC_CHECK(m) ({ \
- bool rc = (((m)[0] != VECTOR_NODE_MAGIC[0]) || \
- ((m)[1] != VECTOR_NODE_MAGIC[1]) || \
- ((m)[2] != VECTOR_NODE_MAGIC[2]) || \
- ((m)[3] != VECTOR_NODE_MAGIC[3])); \
- rc; \
- })
-
-typedef struct vector_node vector_node_t;
-
-struct vector_node {
- uint8_t magic[4];
-
- uint32_t address;
- tree_node_t node;
-
- uint8_t data[];
-};
-
-#define VECTOR_PAGE_MAX UINT16_MAX
-#define VECTOR_PAGE_DIVISOR 32
-
-#define __index_to_page(i,s) \
-({ \
- typeof(i) _p = ((i) / (s)); \
- _p; \
-})
-
-#define __index_to_page_hashed(i,s) \
-({ \
- typeof(i) _h = int64_hash1(__index_to_page((i),(s))); \
- _h; \
-})
-/*! @endcond */
-
-/* ======================================================================= */
-
-static vector_node_t *__vector_find_page(vector_t * self, uint64_t idx)
-{
- const void *hash;
- hash = (const void *)__index_to_page_hashed(idx, self->hdr.elem_num);
-
- tree_node_t *node = tree_find(&self->tree, hash);
- if (unlikely(node == NULL)) {
- UNEXPECTED("'%ld' index out of range", idx);
- return NULL;
- }
-
- return container_of(node, vector_node_t, node);
-}
-
-static int __vector_shrink(vector_t * self)
-{
- assert(self != NULL);
-
- vector_node_t *node = __vector_find_page(self,
- vector_capacity(self) - 1);
- assert(node != NULL);
-
- int rc = splay_remove(&self->tree, &node->node);
-
- free(node);
- self->hdr.page_count--;
-
- return rc;
-}
-
-static vector_node_t *__vector_grow(vector_t * self)
-{
- assert(self != NULL);
- assert(!MAGIC_CHECK(self->hdr.id, VECTOR_MAGIC));
-
- vector_node_t *node = NULL;
- int rc = posix_memalign((void **)&node, sizeof(void *),
- self->hdr.page_size);
- if (rc != 0) {
- ERRNO(errno);
- return NULL;
- }
-
- memset(node, 0, self->hdr.page_size);
-
- node->magic[0] = VECTOR_NODE_MAGIC[0];
- node->magic[1] = VECTOR_NODE_MAGIC[1];
- node->magic[2] = VECTOR_NODE_MAGIC[2];
- node->magic[3] = VECTOR_NODE_MAGIC[3];
-
- node->address = (ulong) node;
-
- uint64_t hash = __index_to_page_hashed(vector_capacity(self),
- self->hdr.elem_num);
-
- tree_node_init(&node->node, (const void *)hash);
- if (splay_insert(&self->tree, &node->node) < 0) {
- free(node);
- return NULL;
- }
- self->hdr.page_count++;
-
- return node;
-}
-
-static int __vector_compare(const int i1, const int i2)
-{
- return i1 - i2;
-}
-
-/* ======================================================================= */
-
-int vector_init3(vector_t * self, const char *name, uint32_t elem_size)
-{
- uint32_t page_size = max(sysconf(_SC_PAGESIZE),
- __round_pow2(elem_size * VECTOR_PAGE_DIVISOR));
- return vector_init4(self, name, elem_size, page_size);
-}
-
-int vector_init4(vector_t * self, const char *name, uint32_t elem_size,
- uint32_t page_size)
-{
- assert(self != NULL);
-
- if (unlikely(MAGIC_CHECK(self->hdr.id, VECTOR_MAGIC)) == false)
- vector_delete(self);
-
- if (elem_size < VECTOR_ELEM_MIN || VECTOR_ELEM_MAX < elem_size) {
- UNEXPECTED("'%d' elem_size out of range [%d..%d]",
- elem_size, VECTOR_ELEM_MIN, VECTOR_ELEM_MAX);
- return -1;
- }
-
- page_size = __round_pow2(page_size);
- if (page_size / elem_size < VECTOR_PAGE_DIVISOR) {
- UNEXPECTED("'%d' page_size out of range [%d..%d]",
- page_size, elem_size * VECTOR_PAGE_DIVISOR,
- VECTOR_PAGE_MAX);
- return -1;
- }
-
- memset(self, 0, sizeof *self);
-
- self->hdr.id[IDENT_MAGIC_0] = VECTOR_MAGIC[IDENT_MAGIC_0];
- self->hdr.id[IDENT_MAGIC_1] = VECTOR_MAGIC[IDENT_MAGIC_1];
- self->hdr.id[IDENT_MAGIC_2] = VECTOR_MAGIC[IDENT_MAGIC_2];
- self->hdr.id[IDENT_MAGIC_3] = VECTOR_MAGIC[IDENT_MAGIC_3];
-
- self->hdr.id[IDENT_MAJOR] = CLIB_MAJOR;
- self->hdr.id[IDENT_MINOR] = CLIB_MINOR;
- self->hdr.id[IDENT_PATCH] = CLIB_PATCH;
-
- if (__BYTE_ORDER == __LITTLE_ENDIAN)
- self->hdr.id[IDENT_FLAGS] |= VECTOR_FLAG_LSB;
- if (__BYTE_ORDER == __BIG_ENDIAN)
- self->hdr.id[IDENT_FLAGS] |= VECTOR_FLAG_MSB;
-
- self->hdr.page_size = page_size;
- self->hdr.elem_size = elem_size;
- self->hdr.elem_num = (self->hdr.page_size - sizeof(vector_node_t)) /
- self->hdr.elem_size;
-
- if (name != NULL && *name != '\0')
- strncpy(self->hdr.name, name, sizeof(self->hdr.name));
-
- tree_init(&self->tree, (compare_f) __vector_compare);
-
- return 0;
-}
-
-int vector_delete(vector_t * self)
-{
- if (unlikely(self == NULL))
- return 0;
-
- assert(!MAGIC_CHECK(self->hdr.id, VECTOR_MAGIC));
-
- tree_iter_t it;
- tree_iter_init(&it, &self->tree, TI_FLAG_FWD);
-
- vector_node_t *node;
- tree_for_each(&it, node, node) {
- if (VECTOR_NODE_MAGIC_CHECK(node->magic)) {
- UNEXPECTED("'%s' invalid or corrupt vector_node"
- "object => '%.4s'", self->hdr.name,
- node->magic);
- return -1;
- }
-
- if (splay_remove(&self->tree, &node->node) < 0)
- return -1;
-
- memset(node, 0, sizeof(*node));
- free(node);
- }
-
- self->hdr.page_count = self->hdr.size = 0;
-
- return 0;
-}
-
-const void *vector_at(vector_t * self, uint32_t idx)
-{
- assert(self != NULL);
- assert(!MAGIC_CHECK(self->hdr.id, VECTOR_MAGIC));
- assert(idx < self->hdr.size);
-
- vector_node_t *node = __vector_find_page(self, idx);
- return node->data + (self->hdr.elem_size * (idx % self->hdr.elem_num));
-}
-
-int vector_get3(vector_t * self, uint32_t idx, void *ptr)
-{
- return vector_get4(self, idx, ptr, 1);
-}
-
-int vector_get4(vector_t * self, uint32_t idx, void *ptr, uint32_t count)
-{
- assert(self != NULL);
- assert(!MAGIC_CHECK(self->hdr.id, VECTOR_MAGIC));
-
- while (0 < count) {
- memcpy(ptr, vector_at(self, idx), self->hdr.elem_size);
-
- idx++;
- count--;
-
- ptr += self->hdr.elem_size;
- }
-
- return 0;
-}
-
-static inline int __vector_put(vector_t * self, uint32_t idx, const void *ptr)
-{
- assert(self != NULL);
- assert(!MAGIC_CHECK(self->hdr.id, VECTOR_MAGIC));
-
- vector_node_t *node = __vector_find_page(self, idx);
- assert(node != NULL);
-
- if (VECTOR_NODE_MAGIC_CHECK(node->magic)) {
- UNEXPECTED("'%s' invalid or corrupt vector_node object => "
- "'%.4s'", self->hdr.name, node->magic);
- return -1;
- }
-
- memcpy(node->data + (self->hdr.elem_size * (idx % self->hdr.elem_num)),
- ptr, self->hdr.elem_size);
-
- return 0;
-}
-
-int vector_put3(vector_t * self, uint32_t idx, const void *ptr)
-{
- return vector_put4(self, idx, ptr, 1);
-}
-
-int vector_put4(vector_t * self, uint32_t idx, const void *ptr, uint32_t count)
-{
- assert(self != NULL);
- assert(!MAGIC_CHECK(self->hdr.id, VECTOR_MAGIC));
- assert(idx < self->hdr.size);
-
- while (0 < count) {
- if (__vector_put(self, idx, ptr) < 0)
- return -1;
-
- idx++;
- count--;
-
- ptr += self->hdr.elem_size;
- }
-
- return 0;
-}
-
-uint32_t vector_size1(vector_t * self)
-{
- assert(self != NULL);
- return self->hdr.size;
-}
-
-int vector_size2(vector_t * self, uint32_t size)
-{
- assert(self != NULL);
- assert(!MAGIC_CHECK(self->hdr.id, VECTOR_MAGIC));
-
- size_t pages = __index_to_page(size, self->hdr.elem_num) + 1;
-
- if (vector_pages(self) < pages) {
- while (vector_pages(self) < pages)
- (void)__vector_grow(self);
- } else if (pages < vector_pages(self)) {
- if (size <= 0)
- vector_delete(self);
- else
- while (pages < vector_pages(self))
- if (__vector_shrink(self) < 0)
- return -1;
- }
-
- return self->hdr.size = size;
-}
-
-uint32_t vector_pages(vector_t * self)
-{
- assert(self != NULL);
- assert(!MAGIC_CHECK(self->hdr.id, VECTOR_MAGIC));
- return self->hdr.page_count;
-}
-
-uint32_t vector_capacity(vector_t * self)
-{
- assert(self != NULL);
- assert(!MAGIC_CHECK(self->hdr.id, VECTOR_MAGIC));
- return self->hdr.page_count * self->hdr.elem_num;
-}
-
-uint32_t vector_elem_size(vector_t * self)
-{
- assert(self != NULL);
- assert(!MAGIC_CHECK(self->hdr.id, VECTOR_MAGIC));
- return self->hdr.elem_size;
-}
-
-ssize_t vector_save(vector_t * self, FILE * out)
-{
- assert(self != NULL);
- assert(out != NULL);
- assert(!MAGIC_CHECK(self->hdr.id, VECTOR_MAGIC));
-
- int header_swap(vector_header_t * hdr) {
- assert(hdr != NULL);
-
- if (hdr->id[IDENT_FLAGS] & VECTOR_FLAG_MSB) {
- hdr->page_size = htobe32(hdr->page_size);
- hdr->elem_size = htobe16(hdr->elem_size);
- hdr->elem_num = htobe16(hdr->elem_num);
- hdr->size = htobe32(hdr->size);
- hdr->page_count = htobe32(hdr->page_count);
- } else if (hdr->id[IDENT_FLAGS] & VECTOR_FLAG_LSB) {
- hdr->page_size = htole32(hdr->page_size);
- hdr->elem_size = htole16(hdr->elem_size);
- hdr->elem_num = htole16(hdr->elem_num);
- hdr->size = htole32(hdr->size);
- hdr->page_count = htole32(hdr->page_count);
- } else {
- UNEXPECTED("'%s' invalid or corrupt flash object => "
- "'%x'", hdr->name, hdr->id[IDENT_FLAGS]);
- return -1;
- }
-
- return 0;
- }
-
- ssize_t save(vector_t * self, FILE * out) {
- tree_iter_t it;
- tree_iter_init(&it, &self->tree, TI_FLAG_FWD);
-
- ssize_t len = 0;
-
- vector_node_t *node;
- tree_for_each(&it, node, node) {
- if (VECTOR_NODE_MAGIC_CHECK(node->magic)) {
- UNEXPECTED("'%s' invalid or corrupt vector_node"
- "object => '%.4s'", self->hdr.name,
- node->magic);
- return -1;
- }
-
- size_t rc;
-
- vector_node_t copy = *node;
-
- copy.address = 0;
- copy.node.left = copy.node.right = NULL;
- copy.node.parent = NULL;
-
- rc = fwrite((char *)&copy, 1, sizeof(copy), out);
- if (rc != sizeof(copy)) {
- if (ferror(out)) {
- ERRNO(errno);
- return -1;
- }
- }
- len += rc;
-
- rc = fwrite((char *)node->data, 1,
- self->hdr.page_size - sizeof(*node), out);
- if (rc != self->hdr.page_size - sizeof(*node)) {
- if (ferror(out)) {
- ERRNO(errno);
- return -1;
- }
- }
- len += rc;
- }
-
- return len;
- }
-
- ssize_t total = 0;
-
- vector_header_t hdr = self->hdr;
- if (header_swap(&hdr) < 0)
- return -1;
-
- clearerr(out);
- total = fwrite(&hdr, 1, sizeof(hdr), out);
- if (total != sizeof(hdr)) {
- if (ferror(out)) {
- ERRNO(errno);
- return -1;
- }
- }
-
- total += save(self, out);
-
- return total;
-}
-
-ssize_t vector_load(vector_t * self, FILE * in)
-{
- assert(self != NULL);
- assert(in != NULL);
- assert(!MAGIC_CHECK(self->hdr.id, VECTOR_MAGIC));
-
- int header_swap(vector_header_t * hdr) {
- assert(hdr != NULL);
-
- if (hdr->id[IDENT_FLAGS] & VECTOR_FLAG_MSB) {
- hdr->page_size = be32toh(hdr->page_size);
- hdr->elem_size = be16toh(hdr->elem_size);
- hdr->elem_num = be16toh(hdr->elem_num);
- hdr->size = be32toh(hdr->size);
- hdr->page_count = be32toh(hdr->page_count);
- } else if (hdr->id[IDENT_FLAGS] & VECTOR_FLAG_LSB) {
- hdr->page_size = le32toh(hdr->page_size);
- hdr->elem_size = le16toh(hdr->elem_size);
- hdr->elem_num = le16toh(hdr->elem_num);
- hdr->size = le32toh(hdr->size);
- hdr->page_count = le32toh(hdr->page_count);
- } else {
- UNEXPECTED("'%s' invalid or corrupt flash object => "
- "'%x'", hdr->name, hdr->id[IDENT_FLAGS]);
- return -1;
- }
-
- return 0;
- }
-
- vector_delete(self);
-
- clearerr(in);
- ssize_t len = fread(&self->hdr, 1, sizeof(self->hdr), in);
- if (len != sizeof(self->hdr)) {
- if (feof(in)) {
- UNEXPECTED("'%s' end-of-file encountered",
- self->hdr.name);
- return -1;
- }
- if (ferror(in)) {
- ERRNO(errno);
- return -1;
- }
- }
-
- if (header_swap(&self->hdr) < 0)
- return -1;
-
- assert(!MAGIC_CHECK(self->hdr.id, VECTOR_MAGIC));
-
- tree_init(&self->tree, (compare_f) __vector_compare);
- vector_node_t *node = NULL;
-
- for (size_t i = 0; i < vector_pages(self); i++) {
- size_t rc = posix_memalign((void **)&node, sizeof(void *),
- self->hdr.page_size);
- if (rc != 0) {
- ERRNO(errno);
- return -1;
- }
- memset(node, 0, self->hdr.page_size);
-
- rc = fread((void *)node, 1, self->hdr.page_size, in);
- if (rc != self->hdr.page_size) {
- if (feof(in)) {
- UNEXPECTED("'%s' end-of-file encountered",
- self->hdr.name);
- return -1;
- }
- if (ferror(in)) {
- ERRNO(errno);
- return -1;
- }
- }
-
- len += rc;
-
- if (VECTOR_NODE_MAGIC_CHECK(node->magic)) {
- UNEXPECTED("'%s' invalid or corrupt vector_node "
- "object => '%.4s'", self->hdr.name,
- node->magic);
- return -1;
- }
-
- node->address = (ulong) node;
- tree_node_init(&node->node, node->node.key);
- splay_insert(&self->tree, &node->node);
-
- node = NULL;
- }
-
- return len;
-}
-
-int vector_send(vector_t * self, mqueue_t * mq)
-{
- assert(self != NULL);
- assert(mq != NULL);
- assert(!MAGIC_CHECK(self->hdr.id, VECTOR_MAGIC));
-
- mqueue_send(mq, (char *)self, sizeof(*self));
-
- tree_iter_t it;
- tree_iter_init(&it, &self->tree, TI_FLAG_FWD);
-
- vector_node_t *node;
- tree_for_each(&it, node, node) {
- assert(!VECTOR_NODE_MAGIC_CHECK(node->magic));
- mqueue_send(mq, (char *)node, self->hdr.page_size);
- }
-
- return 0;
-}
-
-int vector_receive(vector_t * self, mqueue_t * mq)
-{
- assert(self != NULL);
- assert(mq != NULL);
- assert(!MAGIC_CHECK(self->hdr.id, VECTOR_MAGIC));
-
- vector_delete(self);
-
- mqueue_attr_t attr = mqueue_getattr(mq);
-
- vector_node_t *node = NULL;
- size_t rc = posix_memalign((void **)&node, attr.mq_msgsize,
- attr.mq_msgsize);
- if (rc != 0) {
- ERRNO(errno);
- return -1;
- }
-
- ssize_t len = mqueue_receive(mq, (void *)node, attr.mq_msgsize);
- assert(0 < len);
-
- assert(!MAGIC_CHECK(self->hdr.id, VECTOR_MAGIC));
-
- memcpy(self, (void *)node, sizeof(*self));
- tree_init(&self->tree, (compare_f) __vector_compare);
-
- for (size_t i = 0; i < vector_pages(self); i++) {
- rc = posix_memalign((void **)&node, attr.mq_msgsize,
- attr.mq_msgsize);
- if (rc != 0) {
- ERRNO(errno);
- return -1;
- }
-
- len = mqueue_receive(mq, (void *)node, attr.mq_msgsize);
- assert(0 < len);
-
- assert(!VECTOR_NODE_MAGIC_CHECK(node->magic));
-
- node->address = (ulong) node;
- tree_node_init(&node->node, node->node.key);
- splay_insert(&self->tree, &node->node);
-
- node = NULL;
- }
-
- return 0;
-}
-
-void vector_dump(vector_t * self, FILE * out)
-{
- if (out == NULL)
- out = stdout;
-
- if (self != NULL) {
- assert(!unlikely(MAGIC_CHECK(self->hdr.id, VECTOR_MAGIC)));
-
- fprintf(out, "%s: page_size: %d elem_size: %d elem_num: %d -- "
- "size: %d capacity: %d -- page_count: %d\n",
- self->hdr.name, self->hdr.page_size,
- self->hdr.elem_size, self->hdr.elem_num,
- vector_size(self), vector_capacity(self),
- self->hdr.page_count);
-
- tree_iter_t it;
- tree_iter_init(&it, &self->tree, TI_FLAG_FWD);
-
- vector_node_t *node;
- tree_for_each(&it, node, node) {
- fprintf(out, "magic[%.4s] node: %p data: %p -- "
- "address: %x\n", node->magic, &node->node,
- node->data, node->address);
-
- dump_memory(out, (unsigned long)node, node,
- self->hdr.page_size);
- }
- }
-}
-
-/* ======================================================================= */
diff --git a/clib/src/vector_iter.c b/clib/src/vector_iter.c
deleted file mode 100644
index f3db641..0000000
--- a/clib/src/vector_iter.c
+++ /dev/null
@@ -1,184 +0,0 @@
-/* IBM_PROLOG_BEGIN_TAG */
-/* This is an automatically generated prolog. */
-/* */
-/* $Source: clib/src/vector_iter.c $ */
-/* */
-/* OpenPOWER FFS Project */
-/* */
-/* Contributors Listed Below - COPYRIGHT 2014,2015 */
-/* [+] International Business Machines Corp. */
-/* */
-/* */
-/* Licensed under the Apache License, Version 2.0 (the "License"); */
-/* you may not use this file except in compliance with the License. */
-/* You may obtain a copy of the License at */
-/* */
-/* http://www.apache.org/licenses/LICENSE-2.0 */
-/* */
-/* Unless required by applicable law or agreed to in writing, software */
-/* distributed under the License is distributed on an "AS IS" BASIS, */
-/* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or */
-/* implied. See the License for the specific language governing */
-/* permissions and limitations under the License. */
-/* */
-/* IBM_PROLOG_END_TAG */
-
-/*
- * File: vector_iter.c
- * Author: Shaun Wetzstein <shaun@us.ibm.com>
- * Descr: dynamic array
- * Note:
- * Date: 10/22/10
- */
-
-#include <unistd.h>
-#include <stdarg.h>
-#include <stdlib.h>
-#include <malloc.h>
-#include <stdint.h>
-#include <stdio.h>
-#include <string.h>
-#include <errno.h>
-#include <limits.h>
-
-#include "libclib.h"
-#include "vector_iter.h"
-
-/* ======================================================================= */
-
-static inline const void *__vector_iter_bwd(vector_iter_t * self)
-{
- size_t low = 0;
- const void *ret = NULL;
-
- if (low < self->idx)
- self->idx--;
-
- if (low < self->idx)
- ret = vector_at(self->vector, self->idx);
-
- return ret;
-}
-
-static inline const void *__vector_iter_fwd(vector_iter_t * self)
-{
- size_t high = vector_size(self->vector);
- const void *ret = NULL;
-
- if (self->idx < high)
- self->idx++;
-
- if (self->idx < high)
- ret = vector_at(self->vector, self->idx);
-
- return ret;
-}
-
-int vector_iter_init(vector_iter_t * self, vector_t * vector, uint32_t flags)
-{
- assert(self != NULL);
- assert(vector != NULL);
-
- self->flags = flags;
- self->vector = vector;
-
- if (self->flags & VI_FLAG_BWD) {
- self->idx = vector_size(self->vector);
- __vector_iter_bwd(self);
- } else {
- self->idx = 0;
- }
-
- return 0;
-}
-
-int vector_iter_clear(vector_iter_t * self)
-{
- assert(self != NULL);
-
- if (self->flags & VI_FLAG_BWD)
- self->idx = vector_size(self->vector);
- else
- self->idx = 0;
-
- self->vector = NULL;
- return 0;
-}
-
-const void *vector_iter_elem(vector_iter_t * self)
-{
- assert(self != NULL);
-
- if (vector_capacity(self->vector) <= self->idx) {
- UNEXPECTED("'%d' index out-of-range", self->idx);
- return NULL;
- }
-
- if (vector_size(self->vector) <= self->idx)
- return NULL;
-
- return vector_at(self->vector, self->idx);
-}
-
-const void *vector_iter_inc1(vector_iter_t * self)
-{
- return vector_iter_inc2(self, 1);
-}
-
-const void *vector_iter_inc2(vector_iter_t * self, size_t count)
-{
- assert(self != NULL);
-
- const void *ret = NULL;
-
- for (size_t i = 0; i < count; i++) {
- if (self->flags & VI_FLAG_BWD)
- ret = __vector_iter_bwd(self);
- else
- ret = __vector_iter_fwd(self);
- }
-
- return ret;
-}
-
-const void *vector_iter_dec1(vector_iter_t * self)
-{
- return vector_iter_dec2(self, 1);
-}
-
-const void *vector_iter_dec2(vector_iter_t * self, size_t count)
-{
- assert(self != NULL);
-
- const void *ret = NULL;
-
- for (size_t i = 0; i < count; i++) {
- if (self->flags & VI_FLAG_BWD)
- ret = __vector_iter_fwd(self);
- else
- ret = __vector_iter_bwd(self);
- }
-
- return ret;
-}
-
-size_t vector_iter_pos1(vector_iter_t * self)
-{
- assert(self != NULL);
- return self->idx;
-}
-
-int vector_iter_pos2(vector_iter_t * self, size_t pos)
-{
- assert(self != NULL);
-
- if (vector_size(self->vector) <= pos) {
- UNEXPECTED("'%ld' index out-of-range", pos);
- return -1;
- }
-
- self->idx = pos;
- return 0;
-}
-
-/* ======================================================================= */
diff --git a/clib/test/vector.c b/clib/test/vector.c
deleted file mode 100644
index 262f1cf..0000000
--- a/clib/test/vector.c
+++ /dev/null
@@ -1,90 +0,0 @@
-/* IBM_PROLOG_BEGIN_TAG */
-/* This is an automatically generated prolog. */
-/* */
-/* $Source: clib/test/vector.c $ */
-/* */
-/* OpenPOWER FFS Project */
-/* */
-/* Contributors Listed Below - COPYRIGHT 2014,2015 */
-/* [+] International Business Machines Corp. */
-/* */
-/* */
-/* Licensed under the Apache License, Version 2.0 (the "License"); */
-/* you may not use this file except in compliance with the License. */
-/* You may obtain a copy of the License at */
-/* */
-/* http://www.apache.org/licenses/LICENSE-2.0 */
-/* */
-/* Unless required by applicable law or agreed to in writing, software */
-/* distributed under the License is distributed on an "AS IS" BASIS, */
-/* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or */
-/* implied. See the License for the specific language governing */
-/* permissions and limitations under the License. */
-/* */
-/* IBM_PROLOG_END_TAG */
-
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-
-#include <clib/vector.h>
-#include <clib/vector_iter.h>
-
-int main(void) {
- vector_t a = INIT_VECTOR;
- vector_init(&a, "foo", 4, 1024);
-
- vector_size(&a, 1000);
-
- vector_put(&a, 0, (uint32_t[]){0xffffffff});
- vector_put(&a, 1, (uint32_t[]){0xffffffff});
- vector_put(&a, 52, (uint32_t[]){52});
- vector_put(&a, 53, (uint32_t[]){53});
- vector_put(&a, 167, (uint32_t[]){167});
- vector_put(&a, 223, (uint32_t[]){223});
- vector_put(&a, 78, (uint32_t[]){78});
- vector_put(&a, 205, (uint32_t[]){205});
- vector_put(&a, 183, (uint32_t[]){183});
- vector_put(&a, 150, (uint32_t[]){150});
- vector_put(&a, 90, (uint32_t[]){90});
- vector_put(&a, 66, (uint32_t[]){66});
- vector_put(&a, 91, (uint32_t[]){91});
- vector_put(&a, 45, (uint32_t[]){45});
- vector_put(&a, 211, (uint32_t[]){211});
-
- uint32_t arr[] = {985,986,987,988,990,991,992,993,994};
- vector_put(&a, 985, arr, 9);
-
- vector_dump(&a, stdout);
-
- vector_size(&a, 200);
-
- vector_dump(&a, stdout);
-
- FILE *f = fopen("vector.bin", "w+");
- vector_save(&a, f);
- fclose(f);
-
- vector_delete(&a);
-
- f = fopen("vector.bin", "r");
- vector_load(&a, f);
- fclose(f);
-
-#if 1
- vector_iter_t it;
- vector_iter_init(&it, &a, VI_FLAG_FWD);
-
- uint32_t * j;
- vector_for_each(&it, j) {
- printf("arr[%d] = %d\n", it.idx, *j);
- }
-#endif
-
- vector_dump(&a, stdout);
-
- vector_delete(&a);
-
- return 0;
-}
diff --git a/clib/vector.h b/clib/vector.h
deleted file mode 100644
index 1d39b4f..0000000
--- a/clib/vector.h
+++ /dev/null
@@ -1,439 +0,0 @@
-/* IBM_PROLOG_BEGIN_TAG */
-/* This is an automatically generated prolog. */
-/* */
-/* $Source: clib/vector.h $ */
-/* */
-/* OpenPOWER FFS Project */
-/* */
-/* Contributors Listed Below - COPYRIGHT 2014,2015 */
-/* [+] International Business Machines Corp. */
-/* */
-/* */
-/* Licensed under the Apache License, Version 2.0 (the "License"); */
-/* you may not use this file except in compliance with the License. */
-/* You may obtain a copy of the License at */
-/* */
-/* http://www.apache.org/licenses/LICENSE-2.0 */
-/* */
-/* Unless required by applicable law or agreed to in writing, software */
-/* distributed under the License is distributed on an "AS IS" BASIS, */
-/* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or */
-/* implied. See the License for the specific language governing */
-/* permissions and limitations under the License. */
-/* */
-/* IBM_PROLOG_END_TAG */
-
-/*!
- * @file vector.h
- * @brief Vector container
- * @details Vectors are a container whose elements are in sequential order
- * @details For example,
- * @code
- * #include <clib/vector.h>
- * #include <clib/vector_iter.h>
- *
- * int main(const int argc, const char * argv[]) {
- * vector_t a;
- * vector_init(&a, 4, 1024);
- *
- * vector_size(&a, 10);
- *
- * int i;
- * for (i=0; i<10; i++)
- * vector_put(&a, i, &i);
- * vector_put(&a, 223, (uint32_t[]){223});
- *
- * vector_iter_t it;
- * vector_iter_init(&it, &a, VI_FLAG_FWD);
- *
- * uint32_t * j;
- * vector_for_each(&it, j) {
- * printf("vec[%d]\n", *j);
- * }
- *
- * vector_dump(&a, stdout);
- * vector_delete(&a);
- *
- * return 0;
- * }
- * @endcode
- * @author Shaun Wetzstein <shaun@us.ibm.com>
- * @date 2010-2011
- */
-
-#ifndef __VECTOR_H__
-#define __VECTOR_H__
-
-#include <sys/uio.h>
-
-#include <stdbool.h>
-#include <stdint.h>
-
-#include "version.h"
-#include "nargs.h"
-#include "ident.h"
-#include "mq.h"
-#include "tree.h"
-
-/* ======================================================================= */
-
-#define VECTOR_MAGIC "VCTR"
-
-#define VECTOR_NAME_SIZE 40 //!< Maximum vector name size (in bytes)
-
-#define VECTOR_FLAG_LSB 0x01 //!< Little-endian header data
-#define VECTOR_FLAG_MSB 0x02 //!< Big-endian header data
-
-#define VECTOR_ELEM_MIN 1 //!< Minimum element size (in bytes)
-#define VECTOR_ELEM_MAX 8192 //!< Maximum element size (in bytes)
-
-#define INIT_VECTOR_HEADER {INIT_IDENT,{0,},0,0,0,0,0}
-#define INIT_VECTOR {INIT_VECTOR_HEADER, INIT_TREE}
-
-/*!
- * @brief vector container header
- */
-struct vector_header {
- ident_t id; //!< identification
- char name[VECTOR_NAME_SIZE]; //!< vector name
-
- uint32_t page_size; //!< data page size (in bytes)
- uint32_t page_count; //!< number of data pages allocated (currently)
-
- uint32_t elem_size; //!< element size (in bytes)
- uint32_t elem_num; //!< element count (per page)
-
- uint32_t size; //!< number of initialized elements
-};
-typedef struct vector_header vector_header_t; //!< Alias for the @em vector_header class
-
-/*!
- * @brief vector container
- */
-struct vector { //! The vector class
- vector_header_t hdr; //!< Table metadata
-
- tree_t tree; //!< @private
-};
-typedef struct vector vector_t; //!< Alias for the @em vector class
-
-/* ======================================================================= */
-
-/*!
- * @fn void vector_init(vector_t * self, const char * name, uint32_t elem_size [, uint32_t page_size])
- * @brief Constructs an @em vector container object
- * @details For example,
- * @code
- * ...
- * vector_t ar;
- * vector_init(&ar, 4, 1024);
- * ...
- * @endcode
- * @memberof vector
- * @param self [in] vector object @em self pointer
- * @param name [in] vector object @em name string
- * @param elem_size [in] vector element size, in bytes
- * @param page_size [in] size of page, in bytes
- * @return None
- * @throws UNEXPECTED if @em self pointer is NULL
- */
-/*! @cond */
-#define vector_init(...) STRCAT(vector_init, NARGS(__VA_ARGS__))(__VA_ARGS__)
-extern int vector_init3(vector_t *, const char *, uint32_t)
-/*! @cond */
-__nonnull((1)) /*! @endcond */ ;
-extern int vector_init4(vector_t *, const char *, uint32_t, uint32_t)
-/*! @cond */
-__nonnull((1)) /*! @endcond */ ;
-/*! @endcond */
-
-/*!
- * @brief Destructs an @em vector container object
- * @details Deallocate all backing storage associated with this \em vector object
- * @details For example,
- * @code
- * ...
- * vector_init(&ar, 4, 1024);
- * vector_put(&ar, 524, &count);
- * vector_delete(&ar);
- * ...
- * @endcode
- * @memberof vector
- * @param self [in] vector object @em self pointer
- * @return None
- */
-extern int vector_delete(vector_t *)
-/*! @cond */
-__nonnull((1)) /*! @endcond */ ;
-
-/*!
- * @brief Returns a reference to the element at position @em idx in the @em vector
- * @details For example,
- * @code
- * ...
- * vector_init(&ar, 4, 1024);
- * vector_put(&ar, 524, &count);
- * printf("ar[524] = %d\n", *(int *)vector_at(&ar, 524));
- * vector_delete(&ar);
- * ...
- * @endcode
- * @memberof vector
- * @param self [in] vector object @em self pointer
- * @param idx [in] vector element index
- * @return Reference to vector element at @em idx on SUCCESS
- * @throws UNEXPECTED if @em self pointer is NULL
- * @throws UNEXPECTED if vector element at @em idx is uninitialized
- */
-extern const void *vector_at(vector_t *, uint32_t)
-/*! @cond */
-__nonnull((1)) /*! @endcond */ ;
-
-/*!
- * @fn void vector_get(vector_t * self, uint32_t idx, const void * ptr, uint32_t count=1)
- * @brief Copy content from the @em vector
- * @details Copies @em elem_num element(s) starting at position @em elem_off in the source @em vector to destination pointer @em ptr
- * @note If the fourth parameter is omitted, it defaults to 1
- * @details For example,
- * @code
- * ...
- * vector_init(&ar, 4, 1024);
- * vector_put(&ar, 524, &count);
- * vector_get(&ar, 524, &count);
- * vector_delete(&ar);
- * ...
- * @endcode
- * @memberof vector
- * @param self [in] vector object @em self pointer
- * @param idx [in] vector element index
- * @param ptr [out] Destination storage pointer
- * @param count [in] Desgination element count (optional)
- * @return None
- * @throws UNEXPECTED if @em self pointer is NULL
- */
-/*! @cond */
-#define vector_get(...) STRCAT(vector_get, NARGS(__VA_ARGS__))(__VA_ARGS__)
-extern int vector_get3(vector_t *, uint32_t, void *)
-/*! @cond */
-__nonnull((1, 3)) /*! @endcond */ ;
-extern int vector_get4(vector_t *, uint32_t, void *, uint32_t)
-/*! @cond */
-__nonnull((1, 3)) /*! @endcond */ ;
-/*! @endcond */
-
-/*!
- * @fn void vector_put(vector_t * self, uint32_t idx, const void * ptr, uint32_t count=1)
- * @brief Assign new content to the @em vector
- * @details Copies @em elem_num element(s) from source pointer @em ptr to the destination @em vector starting at position @em elem_off
- * @note If the fourth parameter is omitted, it defaults to 1
- * @details For example,
- * @code
- * ...
- * vector_init(&ar, 4, 1024);
- * vector_put(&ar, 524, &count);
- * vector_get(&ar, 524, &count);
- * vector_delete(&ar);
- * ...
- * @endcode
- * @memberof vector
- * @param self [in] vector object @em self pointer
- * @param idx [in] vector element index
- * @param ptr [in] Source storage pointer
- * @param count [in] Source element count (optional)
- * @return None
- * @throws UNEXPECTED if @em self pointer is NULL
- */
-/*! @cond */
-#define vector_put(...) STRCAT(vector_put, NARGS(__VA_ARGS__))(__VA_ARGS__)
-extern int vector_put3(vector_t *, uint32_t, const void *)
-/*! @cond */
-__nonnull((1, 3)) /*! @endcond */ ;
-extern int vector_put4(vector_t *, uint32_t, const void *, uint32_t)
-/*! @cond */
-__nonnull((1, 3)) /*! @endcond */ ;
-/*! @endcond */
-
-/*!
- * @fn uint32_t vector_size(vector_t * self, uint32_t size = 1)
- * @brief Return or set the size of the @em vector
- * @details Return or set the number of allocated elements in the @em vector
- * @details For example,
- * @code
- * ...
- * vector_init(&ar, 4, 1024);
- * vector_size(&ar, 2040);
- * vector_delete(&ar);
- * ...
- * @endcode
- * @memberof vector
- * @param self [in] vector object @em self pointer
- * @param size [in] New vector size
- * @return None
- * @throws UNEXPECTED if @em self pointer is NULL
- */
-/*! @cond */
-#define vector_size(...) STRCAT(vector_size, NARGS(__VA_ARGS__))(__VA_ARGS__)
-extern uint32_t vector_size1(vector_t *)
-/*! @cond */
-__nonnull((1)) /*! @endcond */ ;
-extern int vector_size2(vector_t *, uint32_t)
-/*! @cond */
-__nonnull((1)) /*! @endcond */ ;
-/*! @endcond */
-
-/*!
- * @brief Return pages of the @em vector container
- * @details Return the number of pages in the @em vector container
- * @details For example,
- * @code
- * ...
- * vector_init(&ar, 4, 1024);
- * vector_size(&ar, 2040);
- * printf("pages = %d\n", vector_pages(&ar));
- * vector_delete(&ar);
- * ...
- * @endcode
- * @memberof vector
- * @param self [in] vector object @em self pointer
- * @return The number of pages that conform the vector's content
- * @throws UNEXPECTED if @em self pointer is NULL
- */
-extern uint32_t vector_pages(vector_t *)
-/*! @cond */
-__nonnull((1)) /*! @endcond */ ;
-
-/*!
- * @brief Return capacity of the @em vector
- * @details Return the number of allocated and unallocated elements in the @em vector container
- * @details For example,
- * @code
- * ...
- * vector_init(&ar, 4, 1024);
- * vector_size(&ar, 2040);
- * printf("capacity = %d\n", vector_capacity(&ar));
- * vector_delete(&ar);
- * ...
- * @endcode
- * @memberof vector
- * @param self [in] vector object @em self pointer
- * @return The number of total elements that conform the vector's content
- * @throws UNEXPECTED if @em self pointer is NULL
- */
-extern uint32_t vector_capacity(vector_t *)
-/*! @cond */
-__nonnull((1)) /*! @endcond */ ;
-
-extern uint32_t vector_elem_size(vector_t *)
-/*! @cond */
-__nonnull((1)) /*! @endcond */ ;
-
-/*!
- * @brief Save (write) an @em vector object to a stream
- * @details For example,
- * @code
- * ...
- * vector_init(&ar, 4, 1024);
- * vector_put(&ar, 7, &count);
- * vector_put(&ar, 7000, &count);
- * ...
- * FILE * f = fopen("...", "w");
- * ...
- * vector_save(&ar, f);
- * vector_delete(&ar);
- * ...
- * @endcode
- * @memberof vector
- * @param self [in] vector object @em self pointer
- * @param out [in] save destination stream
- * @return non-0 on success
- * @throws UNEXPECTED if @em self pointer is NULL
- */
-extern ssize_t vector_save(vector_t *, FILE *)
-/*! @cond */
-__nonnull((1, 2)) /*! @endcond */ ;
-
-/*!
- * @brief Load (read) a @em vector object from a stream
- * @details For example,
- * @code
- * ...
- * vector ar;
- * ...
- * FILE * f = fopen("...", "r");
- * ...
- * vector_load(&ar, f);
- * vector_dump(&ar);
- * ...
- * @endcode
- * @memberof vector
- * @param self [in] vector object @em self pointer
- * @param in [in] load source stream
- * @return non-0 on success
- * @throws UNEXPECTED if @em self pointer is NULL
- */
-extern ssize_t vector_load(vector_t *, FILE *)
-/*! @cond */
-__nonnull((1, 2)) /*! @endcond */ ;
-
-/*!
- * @brief Send (write) an @em vector object to a message queue
- * @details For example,
- * @code
- * ...
- * vector_init(&ar, 4, 1024);
- * vector_put(&ar, 7, &count);
- * vector_put(&ar, 7000, &count);
- * ...
- * mqueue mq;
- * mqueue_init(&mq, "my_server");
- * mqueue_create(&mq, gettid());
- * ...
- * vector_send(&ar, &mq);
- * vector_delete(&ar);
- * ...
- * @endcode
- * @memberof vector
- * @param self [in] vector object @em self pointer
- * @return non-0 on success
- * @throws UNEXPECTED if @em self pointer is NULL
- */
-extern int vector_send(vector_t *, mqueue_t *)
-/*! @cond */
-__nonnull((1, 2)) /*! @endcond */ ;
-
-/*!
- * @brief receive (read) an @em vector object from a message queue
- * @details For example,
- * @code
- * ...
- * vector ar;
- * ...
- * mqueue mq;
- * mqueue_open(&mq, path);
- * ...
- * vector_receive(&ar, &mq);
- * vector_dump(&ar);
- * ...
- * @endcode
- * @memberof vector
- * @param self [in] vector object @em self pointer
- * @return non-0 on success
- * @throws UNEXPECTED if @em self pointer is NULL
- */
-extern int vector_receive(vector_t *, mqueue_t *)
-/*! @cond */
-__nonnull((1, 2)) /*! @endcond */ ;
-
-/*!
- * @brief Pretty print the contents of an @em vector to stdout
- * @memberof vector
- * @param self [in] vector object @em self pointer
- * @return None
- * @throws UNEXPECTED if @em self pointer is NULL
- */
-extern void vector_dump(vector_t *, FILE *)
-/*! @cond */
-__nonnull((1)) /*! @endcond */ ;
-
-/* ======================================================================= */
-
-#endif /* __VECTOR_H__ */
diff --git a/clib/vector_iter.h b/clib/vector_iter.h
deleted file mode 100644
index 764a7fc..0000000
--- a/clib/vector_iter.h
+++ /dev/null
@@ -1,188 +0,0 @@
-/* IBM_PROLOG_BEGIN_TAG */
-/* This is an automatically generated prolog. */
-/* */
-/* $Source: clib/vector_iter.h $ */
-/* */
-/* OpenPOWER FFS Project */
-/* */
-/* Contributors Listed Below - COPYRIGHT 2014,2015 */
-/* [+] International Business Machines Corp. */
-/* */
-/* */
-/* Licensed under the Apache License, Version 2.0 (the "License"); */
-/* you may not use this file except in compliance with the License. */
-/* You may obtain a copy of the License at */
-/* */
-/* http://www.apache.org/licenses/LICENSE-2.0 */
-/* */
-/* Unless required by applicable law or agreed to in writing, software */
-/* distributed under the License is distributed on an "AS IS" BASIS, */
-/* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or */
-/* implied. See the License for the specific language governing */
-/* permissions and limitations under the License. */
-/* */
-/* IBM_PROLOG_END_TAG */
-
-/*! @file vector_iter.h
- * @brief Vector Iterator
- * @details Vectors are a kind of sequence container. As such, their elements
- * are ordered following a strict linear sequence.
- * @code
- * ...
- * vector_t vec;
- * vector_init(&vec, sizeof(uint32_t), 1024);
- * ...
- * vector_iter_t it;
- * vector_iter_init(&it, &vec, VI_FLAG_FWD);
- *
- * uint32_t * j;
- * vector_for_each(&it, j) {
- * printf("vec[%d] = %d\n", it.idx, *j);
- * }
- * ...
- * @endcode
- * @author Shaun Wetzstein <shaun@us.ibm.com>
- * @date 2010-2011
- */
-
-#ifndef __VECTOR_ITER_H__
-#define __VECTOR_ITER_H__
-
-#include <stdbool.h>
-#include <stdint.h>
-
-#include "builtin.h"
-#include "vector.h"
-
-/* ======================================================================= */
-
-typedef struct vector_iter vector_iter_t; //!< Alias for the @em vector_iter class
-
-/*!
- * @brief vector iterator
- * @details Vector iterator class
- */
-struct vector_iter {
- vector_t *vector; //!< Reference to the target vector object
- uint32_t idx; //!< Current position of the iterator
- uint32_t flags; //!< Iterator configuration flags
-};
-
-/* ======================================================================= */
-
-#define VI_FLAG_NONE 0x00000000 //!< No flag mask
-#define VI_FLAG_FWD 0x00000000 //!< Forward (FWD) flag mask
-#define VI_FLAG_BWD 0x00000002 //!< Backward (BWD) flag mask
-#define VI_FLAG_MASK 0x00000003 //!< All flags mask
-
-/*!
- * @brief Initializes an @em vector_iter iterator object
- * @memberof vector_iter
- * @param self [in] vector_iter object @em self pointer
- * @param vector [in] vector container object to iterate
- * @param flags [in] iterator configuration flags
- * @return None
- * @throws UNEXPECTED if @em self pointer is NULL
- * @throws UNEXPECTED if @em array pointer is NULL
- */
-extern int vector_iter_init(vector_iter_t *, vector_t *, uint32_t)
-/*! @cond */
-__nonnull((1, 2)) /*! @endcond */ ;
-
-/*!
- * @brief Resets an @em vector iterator object
- * @memberof vector_iter
- * @param self [in] vector_iter object @em self pointer
- * @return None
- * @throws UNEXPECTED if @em self pointer is NULL
- */
-extern int vector_iter_clear(vector_iter_t *)
-/*! @cond */
-__nonnull((1)) /*! @endcond */ ;
-
-/*!
- * @brief Return a pointer to @em vector element bytes at the current iterator position
- * @memberof vector_iter
- * @param self [in] vector_iter object @em self pointer
- * @throws UNEXPECTED if @em self pointer is NULL
- */
-extern const void *vector_iter_elem(vector_iter_t *)
-/*! @cond */
-__nonnull((1)) /*! @endcond */ ;
-
-/*!
- * @fn const void * vector_iter_inc(vector_iter_t * self, size_t count)
- * @brief Increment the position of an @em vector iterator
- * @details If the second (2nd) parameter is omitted, the iterator is
- * incremented by one (1) position.
- * @memberof vector_iter
- * @param self [in] vector_iter object @em self pointer
- * @param count [in] Number of positions to increment (optional)
- * @return None
- * @throws UNEXPECTED if @em self pointer is NULL
- */
-/*! @cond */
-#define vector_iter_inc(...) STRCAT(vector_iter_inc, NARGS(__VA_ARGS__))(__VA_ARGS__)
-extern const void *vector_iter_inc1(vector_iter_t *)
-/*! @cond */
-__nonnull((1)) /*! @endcond */ ;
-extern const void *vector_iter_inc2(vector_iter_t *, size_t)
-/*! @cond */
-__nonnull((1)) /*! @endcond */ ;
-/*! @endcond */
-
-/*!
- * @fn const void * vector_iter_dec(vector_iter_t * self, size_t count)
- * @brief decrement the position of an @em vector iterator
- * @note If the second (2nd) parameter is omitted, the iterator is decremented by one (1) position.
- * @memberof vector_iter
- * @param self [in] vector_iter object @em self pointer
- * @param count [in] Number of positions to decrement (optional)
- * @return None
- * @throws UNEXPECTED if @em self pointer is NULL
- */
-/*! @cond */
-#define vector_iter_dec(...) STRCAT(vector_iter_dec, NARGS(__VA_ARGS__))(__VA_ARGS__)
-extern const void *vector_iter_dec1(vector_iter_t *)
-/*! @cond */
-__nonnull((1)) /*! @endcond */ ;
-extern const void *vector_iter_dec2(vector_iter_t *, size_t)
-/*! @cond */
-__nonnull((1)) /*! @endcond */ ;
-/*! @endcond */
-
-/*!
- * @fn const void * vector_iter_pos(vector_iter_t * self, size_t pos)
- * @brief Return or set the iterator position witin the @em vector
- * @details If the second (2nd) parameter is omitted, this functions returns the current position.
- * @memberof vector_iter
- * @param self [in] vector_iter object @em self pointer
- * @param pos [in] new iterator position (optional)
- * @return None
- * @throws UNEXPECTED if @em self pointer is NULL
- */
-/*! @cond */
-#define vector_iter_pos(...) STRCAT(vector_iter_pos, NARGS(__VA_ARGS__))(__VA_ARGS__)
-extern size_t vector_iter_pos1(vector_iter_t *)
-/*! @cond */
-__nonnull((1)) /*! @endcond */ ;
-extern int vector_iter_pos2(vector_iter_t *, size_t)
-/*! @cond */
-__nonnull((1)) /*! @endcond */ ;
-/*! @endcond */
-
-/*!
- * @def vector_for_each(it, i)
- * @hideinitializer
- * @brief Vector for-each algorithm
- * @param it [in] Tree iterator object
- * @param i [in] Tree element variable
- */
-#define vector_for_each(it, i) \
- for (i = (typeof(i))vector_iter_elem(it); \
- i != NULL; \
- i = (typeof(i))vector_iter_inc(it))
-
-/* ======================================================================= */
-
-#endif /* __VECTOR_ITER_H__ */
OpenPOWER on IntegriCloud