From a28718aa941d500d552d49b7778f3686e1cebb3a Mon Sep 17 00:00:00 2001 From: Stewart Smith Date: Tue, 15 Dec 2015 15:45:52 +1100 Subject: remove unused map and map_iter Signed-off-by: Stewart Smith --- clib/cunit/map.c | 308 ------------------------------------------------------- clib/cunit/map.h | 26 ----- clib/map.h | 245 ------------------------------------------- clib/map_iter.h | 164 ----------------------------- clib/test/map.c | 83 --------------- 5 files changed, 826 deletions(-) delete mode 100644 clib/cunit/map.c delete mode 100644 clib/cunit/map.h delete mode 100644 clib/map.h delete mode 100644 clib/map_iter.h delete mode 100644 clib/test/map.c diff --git a/clib/cunit/map.c b/clib/cunit/map.c deleted file mode 100644 index 6162344..0000000 --- a/clib/cunit/map.c +++ /dev/null @@ -1,308 +0,0 @@ -/* IBM_PROLOG_BEGIN_TAG */ -/* This is an automatically generated prolog. */ -/* */ -/* $Source: clib/cunit/map.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 -#include -#include - -#include - -#include -#include -#include - -#include - -#define COUNT 20000 -#define SEED 22 - -slab_t slab; - -typedef struct { - map_node_t node; - int i; - float f; -} data_t; - -static int init_map(void) { - slab_init(&slab, "my_slab", sizeof(data_t), 4096); - return 0; -} - -static int clean_map(void) { - slab_delete(&slab); - return 0; -} - -static void __insert(map_t * t, int i) { - data_t * d = (data_t *)slab_alloc(&slab); - - i %= INT32_MAX; - - d->i = i; - d->f = (float)i; - map_node_init(&d->node, (const void *)(intptr_t)(d->i)); - - if (map_insert(t, &d->node) < 0) { - 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)); - } -} - -static data_t * __remove(map_t * t, int i) { - - i %= INT32_MAX; - - map_node_t * n = map_find(t, (const void *)i); - if (n == NULL) map_dump(t, stdout); - CU_ASSERT_PTR_NOT_NULL_FATAL(n); - - map_remove(t, n); - - data_t * d = container_of(n, data_t, node); - CU_ASSERT_PTR_NOT_NULL_FATAL(n); - - if (0 <= i) - CU_ASSERT((int)d->node.key == i); - - return d; -} - -static int compare(const void * v1, const void * v2) { - const int i1 = (const int)v1, i2 = (const int)v2; - return i1 - i2; -} - -static void map_1(void) { - map_t t; - map_init(&t, compare); - - CU_ASSERT(map_min(&t) == NULL); - CU_ASSERT(map_max(&t) == NULL); - CU_ASSERT(map_empty(&t) == true); - CU_ASSERT(map_size(&t) == 0); -} - -static void map_2(void) { - map_t t; - map_init(&t, compare); - - CU_ASSERT(map_empty(&t) == true); - CU_ASSERT(map_size(&t) == 0); - - for (int i=1; i<=COUNT; i++) - __insert(&t, i); - - CU_ASSERT(map_empty(&t) == false); - CU_ASSERT(map_size(&t) == COUNT); - - for (int i=1; i<=COUNT; i++) { - CU_ASSERT(i == (int)map_min(&t)->key); - CU_ASSERT(COUNT == (int)map_max(&t)->key); - __remove(&t, (int)map_min(&t)->key); - CU_ASSERT(map_size(&t) + i == COUNT); - } - - CU_ASSERT(map_empty(&t) == true); - CU_ASSERT(map_size(&t) == 0); - - for (int i=1; i<=COUNT; i++) - __insert(&t, i); - - CU_ASSERT(map_empty(&t) == false); - CU_ASSERT(map_size(&t) == COUNT); - - for (int i=1; i<=COUNT; i++) { - CU_ASSERT(1 == (int)map_min(&t)->key); - CU_ASSERT(COUNT - i + 1 == (int)map_max(&t)->key); - __remove(&t, (int)map_max(&t)->key); - CU_ASSERT(map_size(&t) + i == COUNT); - } - - CU_ASSERT(map_empty(&t) == true); - CU_ASSERT(map_size(&t) == 0); -} - -static void map_3(void) { - map_t t; - map_init(&t, compare); - - CU_ASSERT(map_empty(&t) == true); - CU_ASSERT(map_size(&t) == 0); - - for (int i=1; i<=COUNT; i++) - __insert(&t, COUNT - i + 1); - - CU_ASSERT(map_empty(&t) == false); - CU_ASSERT(map_size(&t) == COUNT); - - for (int i=1; i<=COUNT; i++) { - CU_ASSERT(1 == (int)map_min(&t)->key); - CU_ASSERT(COUNT - i + 1 == (int)map_max(&t)->key); - __remove(&t, (int)map_max(&t)->key); - CU_ASSERT(map_size(&t) + i == COUNT); - } - - CU_ASSERT(map_empty(&t) == true); - CU_ASSERT(map_size(&t) == 0); - - for (int i=1; i<=COUNT; i++) - __insert(&t, COUNT - i + 1); - - CU_ASSERT(map_empty(&t) == false); - CU_ASSERT(map_size(&t) == COUNT); - - for (int i=1; i<=COUNT; i++) { - CU_ASSERT(i == (int)map_min(&t)->key); - CU_ASSERT(COUNT == (int)map_max(&t)->key); - __remove(&t, (int)map_min(&t)->key); - CU_ASSERT(map_size(&t) + i == COUNT); - } - - CU_ASSERT(map_empty(&t) == true); - CU_ASSERT(map_size(&t) == 0); -} - -static void map_4(void) { - map_t t; - map_init(&t, compare); - - CU_ASSERT(map_empty(&t) == true); - CU_ASSERT(map_size(&t) == 0); - - srandom(SEED); - for (int i=1; i<=COUNT; i++) - __insert(&t, (int)random()); - - CU_ASSERT(map_empty(&t) == false); - CU_ASSERT(map_size(&t) == COUNT); - - for (int i=1; i<=COUNT; i++) { - __remove(&t, (int)map_min(&t)->key); - CU_ASSERT(map_size(&t) + i == COUNT); - } - - CU_ASSERT(map_empty(&t) == true); - CU_ASSERT(map_size(&t) == 0); - - srandom(SEED); - for (int i=1; i<=COUNT; i++) - __insert(&t, (int)random()); - - CU_ASSERT(map_empty(&t) == false); - CU_ASSERT(map_size(&t) == COUNT); - - for (int i=1; i<=COUNT; i++) { - __remove(&t, (int)map_max(&t)->key); - CU_ASSERT(map_size(&t) + i == COUNT); - } - - CU_ASSERT(map_empty(&t) == true); - CU_ASSERT(map_size(&t) == 0); - - srandom(SEED); - for (int i=1; i<=COUNT; i++) - __insert(&t, (int)random()); - - CU_ASSERT(map_empty(&t) == false); - CU_ASSERT(map_size(&t) == COUNT); - - srandom(SEED); - for (int i=1; i<=COUNT; i++) { - __remove(&t, (int)random()); - CU_ASSERT(map_size(&t) + i == COUNT); - } - - CU_ASSERT(map_empty(&t) == true); - CU_ASSERT(map_size(&t) == 0); -} - -static void map_5(void) { - map_t t; - map_init(&t, compare); - - CU_ASSERT(map_empty(&t) == true); - CU_ASSERT(map_size(&t) == 0); - - srandom(SEED); - for (int i=1; i<=COUNT; i++) - __insert(&t, (int)random()); - - CU_ASSERT(map_empty(&t) == false); - CU_ASSERT(map_size(&t) == COUNT); - - data_t * d; - int key = 0; - - map_iter_t it; - map_iter_init(&it, &t, MI_FLAG_FWD); - map_for_each(&it, d, node) { - CU_ASSERT(key < (int)d->node.key); - key = (int)d->node.key; - } - - key = INT32_MAX; - map_iter_init(&it, &t, MI_FLAG_BWD); - map_for_each(&it, d, node) { - CU_ASSERT((int)d->node.key < key); - key = (int)d->node.key; - } -} - -static void map_6(void) { - map_t t; - map_init(&t, compare); - - CU_ASSERT(map_empty(&t) == true); - CU_ASSERT(map_size(&t) == 0); - - srandom(SEED); - for (int i=1; i<=COUNT; i++) - __insert(&t, (int)random()); - - CU_ASSERT(map_empty(&t) == false); - CU_ASSERT(map_size(&t) == COUNT); - - srandom(SEED); - for (int i=1; i<=COUNT; i++) { - map_node_t * node = map_find(&t, (const void *)random()); - CU_ASSERT_PTR_NOT_NULL_FATAL(node); - } -} - -void map_test(void) { - CU_pSuite suite = CU_add_suite("map", init_map, clean_map); - if (NULL == suite) - return; - - if (CU_add_test(suite, "test of --> map_1", map_1) == NULL) return; - if (CU_add_test(suite, "test of --> map_2", map_2) == NULL) return; - if (CU_add_test(suite, "test of --> map_3", map_3) == NULL) return; - if (CU_add_test(suite, "test of --> map_4", map_4) == NULL) return; - if (CU_add_test(suite, "test of --> map_5", map_5) == NULL) return; - if (CU_add_test(suite, "test of --> map_6", map_6) == NULL) return; -} diff --git a/clib/cunit/map.h b/clib/cunit/map.h deleted file mode 100644 index 11e4007..0000000 --- a/clib/cunit/map.h +++ /dev/null @@ -1,26 +0,0 @@ -/* IBM_PROLOG_BEGIN_TAG */ -/* This is an automatically generated prolog. */ -/* */ -/* $Source: clib/cunit/map.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 map_test(void); diff --git a/clib/map.h b/clib/map.h deleted file mode 100644 index e625ac8..0000000 --- a/clib/map.h +++ /dev/null @@ -1,245 +0,0 @@ -/* IBM_PROLOG_BEGIN_TAG */ -/* This is an automatically generated prolog. */ -/* */ -/* $Source: clib/map.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: map.h - * Author: Shaun Wetzstein - * Descr: Map container - * Note: - * Date: 10/22/10 - */ - -#ifndef __MAP_H__ -#define __MAP_H__ - -#include -#include - -#include "builtin.h" -#include "compare.h" -#include "type.h" - -#include "tree.h" - -/* ==================================================================== */ - -typedef tree_t map_t; //!< Alias for the @em map class -typedef tree_node_t map_node_t; //!< Alias for the @em map_node class - -/*! - * @brief Constructs a @em map_node object - * @memberof map_node - * @param self [in] map_node object @em self pointer - * @param key [in] pointer to key bytes - * @return Reference to an initialized map_node object on SUCCESS - */ -static inline map_node_t *map_node_init(map_node_t *, const void *) -/*! @cond */ -__nonnull((1, 2)) /*! @endcond */ ; - -/*! - * @fn void map_init(map_t * self, compare_f cmp = default_compare) - * @brief Constructs a @em map object - * @memberof map - * @param self [in] map_node object @em self pointer - * @param cmp [in] Reference to the @em map_node compare function - * @return None - * @throws UNEXPECTED if @em self pointer is NULL - */ -/*! @cond */ -#define map_init(...) STRCAT(map_init, NARGS(__VA_ARGS__))(__VA_ARGS__) -static inline int map_init1(map_t *) -/*! @cond */ -__nonnull((1)) /*! @endcond */ ; -static inline int map_init2(map_t *, compare_f) -/*! @cond */ -__nonnull((1, 2)) /*! @endcond */ ; -/*! @endcond */ - -/*! - * @brief Insert a new @em map_node into the @em map container - * @memberof map - * @param self [in] map object @em self pointer - * @param node [in] Reference to the @em map_node to insert - * @return @em true if the @em map_node was inserted, @em false otherwise - * @throws UNEXPECTED if @em self pointer is NULL - * @throws UNEXPECTED if @em map_node.key points to a duplicate key - */ -static inline int map_insert(map_t *, map_node_t *) -/*! @cond */ -__nonnull((1, 2)) /*! @endcond */ ; - -/*! - * @brief Removes a @em map_node from the @em map container - * @memberof map - * @param self [in] map object @em self pointer - * @param node [in] Reference to the @em map_node to remove - * @return @em true if the @em map_node was removed, @em false otherwise - * @throws UNEXPECTED if @em self pointer is NULL - */ -static inline int map_remove(map_t *, map_node_t *) -/*! @cond */ -__nonnull((1, 2)) /*! @endcond */ ; - -/*! - * @brief Find a @em map_node within the @em map container - * @memberof map - * @param self [in] map object @em self pointer - * @param key [in] Reference to the @em key to find - * @return Reference to a @em map_node on SUCCESS, false otherwise - * @throws UNEXPECTED if @em self pointer is NULL - */ -static inline map_node_t *map_find(map_t *, const void *) -/*! @cond */ -__nonnull((1, 2)) /*! @endcond */ ; - -/*! - * @brief Hexdump the contents of a @em map to @em out output stream - * @memberof map - * @param self [in] map object @em self pointer - * @param out [in] Reference to the @em out output stream - * @return None - * @throws UNEXPECTED if @em self pointer is NULL - */ -static inline void map_dump(map_t *, FILE *) -/*! @cond */ -__nonnull((1, 2)) /*! @endcond */ ; - -/*! - * @brief Return whether a @em map container is empty - * @memberof map - * @param self [in] map object @em self pointer - * @return @em true if @em map is empty, false otherwise - */ -static inline bool map_empty(map_t *) -/*! @cond */ -__nonnull((1)) /*! @endcond */ ; - -/*! - * @brief Return the node count of a @em map container - * @memberof map - * @param self [in] map object @em self pointer - * @return @em 0 if @em map is empty, @em non-0 otherwise - */ -static inline size_t map_size(map_t *) -/*! @cond */ -__nonnull((1)) /*! @endcond */ ; - -/*! - * @brief Return the minimum @em map_node of a @em map container - * @memberof map - * @param self [in] map object @em self pointer - * @return Reference to a @em map_node if @em self is non-NULL, NULL otherwise - */ -static inline map_node_t *map_min(map_t *) -/*! @cond */ -__nonnull((1)) /*! @endcond */ ; - -/*! - * @brief Return the maximum @em map_node of a @em map container - * @memberof map - * @param self [in] map object @em self pointer - * @return Reference to a @em map_node if @em self is non-NULL, NULL otherwise - */ -static inline map_node_t *map_max(map_t *) -/*! @cond */ -__nonnull((1)) /*! @endcond */ ; - -/* ==================================================================== */ - -static inline map_node_t *map_node_init(map_node_t * self, const void *key) -{ - return (map_node_t *) tree_node_init((tree_node_t *) self, key); -} - -/* ==================================================================== */ - -static inline int map_init1(map_t * self) -{ - assert(self != NULL); - return tree_init((tree_t *) self, default_compare); -} - -static inline int map_init2(map_t * self, compare_f cmp) -{ - assert(self != NULL); - assert(cmp != NULL); - return tree_init((tree_t *) self, cmp); -} - -static inline int map_insert(map_t * self, map_node_t * node) -{ - assert(self != NULL); - assert(node != NULL); - return splay_insert((tree_t *) self, (tree_node_t *) node); -} - -static inline int map_remove(map_t * self, map_node_t * node) -{ - assert(self != NULL); - assert(node != NULL); - return splay_remove((tree_t *) self, (tree_node_t *) node); -} - -static inline map_node_t *map_find(map_t * self, const void *key) -{ - assert(self != NULL); - assert(key != NULL); - return (map_node_t *) tree_find((tree_t *) self, key); -} - -static inline bool map_empty(map_t * self) -{ - assert(self != NULL); - return tree_empty((tree_t *) self); -} - -static inline void map_dump(map_t * self, FILE * out) -{ - assert(self != NULL); - tree_dump((tree_t *) self, out ? out : stdout); -} - -static inline size_t map_size(map_t * self) -{ - assert(self != NULL); - return tree_size((tree_t *) self); -} - -static inline map_node_t *map_min(map_t * self) -{ - assert(self != NULL); - return tree_min((tree_t *) self); -} - -static inline map_node_t *map_max(map_t * self) -{ - assert(self != NULL); - return tree_max((tree_t *) self); -} - -/* ==================================================================== */ - -#endif /* __MAP_H__ */ diff --git a/clib/map_iter.h b/clib/map_iter.h deleted file mode 100644 index 4940625..0000000 --- a/clib/map_iter.h +++ /dev/null @@ -1,164 +0,0 @@ -/* IBM_PROLOG_BEGIN_TAG */ -/* This is an automatically generated prolog. */ -/* */ -/* $Source: clib/map_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: map_iter.h - * Author: Shaun Wetzstein - * Descr: Iterator for the Map container - * Note: - * Date: 10/22/10 - */ - -#ifndef __MAP_ITER_H__ -#define __MAP_ITER_H__ - -#include -#include - -#include "builtin.h" - -#include "map.h" -#include "tree_iter.h" - -/* ==================================================================== */ - -typedef tree_iter_t map_iter_t; - -/* ==================================================================== */ - -#define MI_FLAG_NONE TI_FLAG_NONE -#define MI_FLAG_FWD TI_FLAG_FWD -#define MI_FLAG_BWD TI_FLAG_BWD - -/*! - * @brief Initializes an @em map_iter iterator object - * @memberof map_iter - * @param self [in] map_iter object @em self pointer - * @param map [in] map container object to iterate - * @param flags [in] iterator configuration flags - * @return None - * @throws UNEXPECTED if @em self pointer is NULL - * @throws UNEXPECTED if @em map pointer is NULL - */ -static inline int map_iter_init(map_iter_t *, map_t *, uint32_t) -/*! @cond */ -__nonnull((1, 2)) /*! @endcond */ ; - -/*! - * @brief Resets an @em map iterator object - * @memberof map_iter - * @param self [in] map_iter object @em self pointer - * @return None - * @throws UNEXPECTED if @em self pointer is NULL - */ -static inline int map_iter_clear(map_iter_t *) -/*! @cond */ -__nonnull((1)) /*! @endcond */ ; - -/*! - * @brief Return a pointer to a @em map_node element at the current iterator - * position - * @memberof map_iter - * @param self [in] map_iter object @em self pointer - * @return non-NULL on success, NULL otherwise - * @throws UNEXPECTED if @em self pointer is NULL - */ -static inline map_node_t *map_iter_elem(map_iter_t *) -/*! @cond */ -__nonnull((1)) /*! @endcond */ ; - -/*! - * @brief Increment the position of an @em map iterator - * @memberof map_iter - * @param self [in] map_iter object @em self pointer - * @param count [in] Number of positions to increment - * @return None - * @throws UNEXPECTED if @em self pointer is NULL - */ -static inline map_node_t *map_iter_inc(map_iter_t *) -/*! @cond */ -__nonnull((1)) /*! @endcond */ ; - -/*! - * @brief Decrement the position of an @em map iterator - * @memberof map_iter - * @param self [in] map_iter object @em self pointer - * @param count [in] Number of positions to decrement - * @return None - * @throws UNEXPECTED if @em self pointer is NULL - */ -static inline map_node_t *map_iter_dec(map_iter_t *) -/*! @cond */ -__nonnull((1)) /*! @endcond */ ; - -/*! - * @def map_for_each(it, i, m) - * @hideinitializer - * @brief Tree for-each algorithm - * @param it [in] Tree iterator object - * @param i [in] Tree element variable - * @param m [in] Member name - */ -#define map_for_each(it, i, m) \ - for (map_iter_clear(it), i = container_of_var(map_iter_elem(it), i, m); \ - map_iter_elem(it) != NULL; \ - i = container_of_var(map_iter_inc(it), i, m)) - -/* ==================================================================== */ - -static inline int map_iter_init(map_iter_t * self, map_t * map, uint32_t flags) -{ - assert(self != NULL); - assert(map != NULL); - return tree_iter_init((tree_iter_t *) self, (tree_t *) map, flags); -} - -int map_iter_clear(map_iter_t * self) -{ - assert(self != NULL); - return tree_iter_clear((tree_iter_t *) self); -} - -static inline map_node_t *map_iter_elem(map_iter_t * self) -{ - assert(self != NULL); - return (map_node_t *) tree_iter_elem((tree_iter_t *) self); -} - -static inline map_node_t *map_iter_inc(map_iter_t * self) -{ - assert(self != NULL); - return (map_node_t *) tree_iter_inc((tree_iter_t *) self); -} - -static inline map_node_t *map_iter_dec(map_iter_t * self) -{ - assert(self != NULL); - return (map_node_t *) tree_iter_dec((tree_iter_t *) self); -} - -/* ==================================================================== */ - -#endif /* __MAP_ITER_H__ */ diff --git a/clib/test/map.c b/clib/test/map.c deleted file mode 100644 index 4ef7ba6..0000000 --- a/clib/test/map.c +++ /dev/null @@ -1,83 +0,0 @@ -/* IBM_PROLOG_BEGIN_TAG */ -/* This is an automatically generated prolog. */ -/* */ -/* $Source: clib/test/map.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 -#include -#include - -#include -#include -#include -#include - -struct data { - map_node_t node; - int i; - float f; -}; -typedef struct data data_t; - -int main (void) { - slab_t s = INIT_SLAB; - slab_init(&s, "my_slab", sizeof(data_t), 0); - - int compare(const int i1, const int i2) { - return i1 - i2; - } - - map_t m; - map_init(&m, (compare_f)compare); - - int i; - for (i=0; i<100; i++) { - data_t * d = (data_t *)slab_alloc(&s); - - printf("i[%d]\n", i); - - d->i = i; - d->f = (float)i; - - map_node_init(&d->node, (const void *)(d->i)); - map_insert(&m, &d->node); - } - -#if 1 - i = 6; - map_node_t * n = map_find(&m, (const void *)(i)); - map_remove(&m, n); - n = map_find(&m, (const void *)i); - - i = 2; - map_find(&m, (const void *)i); - i = 8; - map_find(&m, (const void *)i); -#endif - - map_dump(&m, stdout); - slab_delete(&s); - - return 0; -} - -- cgit v1.2.1