put again eina tests in the source tree

SVN revision: 56193
This commit is contained in:
Vincent Torri 2011-01-16 17:55:41 +00:00
parent 6a5adabb1c
commit d3420a210d
61 changed files with 62611 additions and 2 deletions

View File

@ -41,18 +41,82 @@ eina.spec.in \
m4/ac_attribute.m4 \
m4/efl_benchmark.m4 \
m4/efl_compiler_flag.m4 \
m4/efl_coverage.m4 \
m4/efl_cpu.m4 \
m4/efl_doxygen.m4 \
m4/efl_fnmatch.m4 \
m4/efl_tests.m4 \
m4/efl_threads.m4 \
m4/eina_bench.m4 \
m4/eina_check.m4 \
m4/efl_path_max.m4
.PHONY: doc
.PHONY: doc coverage benchmark
# Documentation
doc:
@echo "entering doc/"
@cd doc && make doc
# Unit tests
if EFL_ENABLE_TESTS
check-local:
@./src/tests/eina_suite
else
check-local:
@echo "reconfigure with --enable-tests"
endif
# Coverage report
if EFL_ENABLE_COVERAGE
lcov-reset:
@rm -rf coverage
@find . -name "*.gcda" -exec rm {} \;
@lcov --directory . --zerocounters
lcov-report:
@mkdir coverage
@lcov --compat-libtool --directory $(top_srcdir)/src --capture --output-file coverage/coverage.info
@lcov -l coverage/coverage.info |grep "\\.h" |cut -d " " -f 2 > coverage/remove
@lcov -r coverage/coverage.info `cat coverage/remove` > coverage/coverage.cleaned.info
@rm coverage/remove
@mv coverage/coverage.cleaned.info coverage/coverage.info
@genhtml -t "$(PACKAGE_STRING)" -o coverage coverage/coverage.info
coverage:
@make lcov-reset
@make check
@make lcov-report
else
lcov-reset:
@echo "reconfigure with --enable-coverage"
lcov-report:
@echo "reconfigure with --enable-coverage"
coverage:
@echo "reconfigure with --enable-tests --enable-coverage"
endif
if EFL_ENABLE_BENCHMARK
benchmark:
@cd src && make benchmark
@mkdir result || true
@cd result && ../src/tests/eina_bench `date +%F_%s`
else
benchmark:
@echo "reconfigure with --enable-benchmark"
endif
clean-local:
@rm -rf coverage benchmark

View File

@ -569,6 +569,20 @@ EINA_CHECK_MODULE([one-big], [${enable_one_big}], [one big])
### Make the debug preprocessor configurable
### Unit tests, coverage and benchmarking
EFL_CHECK_TESTS([enable_tests="yes"], [enable_tests="no"])
EFL_CHECK_COVERAGE([${enable_tests}], [enable_coverage="yes"], [enable_coverage="no"])
EINA_CFLAGS="${EINA_CFLAGS} ${EFL_COVERAGE_CFLAGS}"
EINA_LIBS="${EINA_LIBS} ${EFL_COVERAGE_LIBS}"
if test "x$enable_coverage" = "xyes" ; then
EINA_CFLAGS="${EINA_CFLAGS} ${EFL_DEBUG_CFLAGS}"
fi
EFL_CHECK_BENCHMARK([enable_benchmark="yes"], [enable_benchmark="no"])
EINA_BENCH_MODULE([glib], [${enable_benchmark}], [glib-2.0], [enable_benchmark_glib="yes"], [enable_benchmark_glib="no"])
AC_SUBST(requirement_eina)
### Create the .pc.in file according to the major version
@ -605,6 +619,7 @@ src/modules/mp/pass_through/Makefile
src/modules/mp/fixed_bitmap/Makefile
src/modules/mp/buddy/Makefile
src/modules/mp/one_big/Makefile
src/tests/Makefile
])
AC_OUTPUT
@ -638,6 +653,13 @@ echo " Iconv support........: ${have_iconv}"
echo " File dirfd...........: ${have_dirfd}"
echo
echo " Documentation........: ${build_doc}"
echo " Tests................: ${enable_tests}"
echo " Coverage.............: ${enable_coverage}"
echo " Benchmark............: ${enable_benchmark}"
if test "x${enable_benchmark}" = "xyes" ; then
echo " Glib...............: ${enable_benchmark_glib}"
echo " E17 real data......: ${enable_benchmark_e17}"
fi
echo
echo " CPU Specific Extensions:"
echo " MMX................: ${have_mmx}"

View File

@ -1,3 +1,17 @@
SUBDIRS = lib include modules
SUBDIRS = lib include modules tests
MAINTAINERCLEANFILES = Makefile.in
.PHONY: benchmark
if EFL_ENABLE_BENCHMARK
benchmark: all
cd tests && make eina_bench
else
benchmark:
@echo "reconfigure with --enable-benchmark"
endif

View File

@ -0,0 +1,557 @@
#ifndef _ECORE_DATA_H
# define _ECORE_DATA_H
#include <stdio.h>
/* we need this for size_t */
#include <stddef.h>
#ifdef EAPI
# undef EAPI
#endif
#ifdef _WIN32
# ifdef EFL_ECORE_BUILD
# ifdef DLL_EXPORT
# define EAPI __declspec(dllexport)
# else
# define EAPI
# endif /* ! DLL_EXPORT */
# else
# define EAPI __declspec(dllimport)
# endif /* ! EFL_ECORE_BUILD */
#else
# ifdef __GNUC__
# if __GNUC__ >= 4
# define EAPI __attribute__ ((visibility("default")))
# else
# define EAPI
# endif
# else
# define EAPI
# endif
#endif /* ! _WIN32 */
/**
* @file Ecore_Data.h
* @brief Contains threading, list, hash, debugging and tree functions.
*/
# ifdef __cplusplus
extern "C" {
# endif
#ifndef TRUE
# define TRUE 1
#endif
#ifndef FALSE
# define FALSE 0
#endif
#ifdef FREE
# undef FREE
#endif
#define FREE(ptr) free(ptr); ptr = NULL;
#ifdef IF_FREE
# undef IF_FREE
#endif
#define IF_FREE(ptr) if (ptr) {free(ptr); } ptr = NULL;
/* convenience macros for checking pointer parameters for non-NULL */
#undef CHECK_PARAM_POINTER_RETURN
#define CHECK_PARAM_POINTER_RETURN(sparam, param, ret) \
if (!(param)) \
{ \
printf("***** Developer Warning ***** :\n" \
"\tThis program is calling:\n\n" \
"\t%s();\n\n" \
"\tWith the parameter:\n\n" \
"\t%s\n\n" \
"\tbeing NULL. Please fix your program.", __FUNCTION__, sparam); \
if (getenv("ECORE_ERROR_ABORT")) { abort(); } \
return ret; \
}
#undef CHECK_PARAM_POINTER
#define CHECK_PARAM_POINTER(sparam, param) \
if (!(param)) \
{ \
printf("***** Developer Warning ***** :\n" \
"\tThis program is calling:\n\n" \
"\t%s();\n\n" \
"\tWith the parameter:\n\n" \
"\t%s\n\n" \
"\tbeing NULL. Please fix your program.", __FUNCTION__, sparam); \
if (getenv("ECORE_ERROR_ABORT")) { abort(); } \
return; \
}
# ifdef __sgi
# define __FUNCTION__ "unknown"
# ifndef __cplusplus
# define inline
# endif
# endif
# define ECORE_SORT_MIN 0
# define ECORE_SORT_MAX 1
typedef void (*Ecore_For_Each)(void *value, void *user_data);
# define ECORE_FOR_EACH(function) ((Ecore_For_Each)function)
typedef void (*Ecore_Free_Cb)(void *data);
# define ECORE_FREE_CB(func) ((Ecore_Free_Cb)func)
typedef unsigned int (*Ecore_Hash_Cb)(const void *key);
# define ECORE_HASH_CB(function) ((Ecore_Hash_Cb)function)
typedef int (*Ecore_Compare_Cb)(const void *data1, const void *data2);
# define ECORE_COMPARE_CB(function) ((Ecore_Compare_Cb)function)
typedef struct _ecore_list Ecore_List;
# define ECORE_LIST(list) ((Ecore_List *)list)
typedef struct _ecore_list_node Ecore_List_Node;
# define ECORE_LIST_NODE(node) ((Ecore_List_Node *)node)
typedef struct _ecore_strbuf Ecore_Strbuf;
# define ECORE_STRBUF(buf) ((Ecore_Strbuf *)buf)
struct _ecore_list_node
{
void *data;
struct _ecore_list_node *next;
};
struct _ecore_list
{
Ecore_List_Node *first; /* The first node in the list */
Ecore_List_Node *last; /* The last node in the list */
Ecore_List_Node *current; /* The current node in the list */
Ecore_Free_Cb free_func; /* The callback to free data in nodes */
int nodes; /* The number of nodes in the list */
int index; /* The position from the front of the
list of current node */
};
EAPI int ecore_direct_compare(const void *key1, const void *key2);
EAPI int ecore_str_compare(const void *key1, const void *key2);
EAPI unsigned int ecore_direct_hash(const void *key);
EAPI unsigned int ecore_str_hash(const void *key);
/* Creating and initializing new list structures */
EAPI Ecore_List * ecore_list_new(void);
EAPI int ecore_list_init(Ecore_List *list);
/* Adding items to the list */
EAPI int ecore_list_append(Ecore_List *list, void *_data);
EAPI int ecore_list_prepend(Ecore_List *list, void *_data);
EAPI int ecore_list_insert(Ecore_List *list, void *_data);
EAPI int ecore_list_append_list(Ecore_List *list,
Ecore_List *append);
EAPI int ecore_list_prepend_list(Ecore_List *list,
Ecore_List *prepend);
/* Removing items from the list */
EAPI int ecore_list_remove_destroy(Ecore_List *list);
EAPI void * ecore_list_remove(Ecore_List *list);
EAPI void * ecore_list_first_remove(Ecore_List *list);
EAPI void * ecore_list_last_remove(Ecore_List *list);
/* Retrieve the current position in the list */
EAPI void * ecore_list_current(Ecore_List *list);
EAPI void * ecore_list_first(Ecore_List *list);
EAPI void * ecore_list_last(Ecore_List *list);
EAPI int ecore_list_index(Ecore_List *list);
EAPI int ecore_list_count(Ecore_List *list);
/* Traversing the list */
EAPI int ecore_list_for_each(Ecore_List *list,
Ecore_For_Each function,
void *user_data);
EAPI void * ecore_list_first_goto(Ecore_List *list);
EAPI void * ecore_list_last_goto(Ecore_List *list);
EAPI void * ecore_list_index_goto(Ecore_List *list, int index);
EAPI void * ecore_list_goto(Ecore_List *list, const void *_data);
/* Traversing the list and returning data */
EAPI void * ecore_list_next(Ecore_List *list);
EAPI void * ecore_list_find(Ecore_List *list,
Ecore_Compare_Cb function,
const void *user_data);
/* Sorting the list */
EAPI int ecore_list_sort(Ecore_List *list,
Ecore_Compare_Cb compare,
char order);
EAPI int ecore_list_mergesort(Ecore_List *list,
Ecore_Compare_Cb compare,
char order);
EAPI int ecore_list_heapsort(Ecore_List *list,
Ecore_Compare_Cb compare,
char order);
EAPI void ecore_list_merge(Ecore_List *list, Ecore_List *l2,
Ecore_Compare_Cb, char order);
/* Check to see if there is any data in the list */
EAPI int ecore_list_empty_is(Ecore_List *list);
/* Remove every node in the list without freeing the list itself */
EAPI int ecore_list_clear(Ecore_List *list);
/* Free the list and it's contents */
EAPI void ecore_list_destroy(Ecore_List *list);
/* Creating and initializing list nodes */
EAPI Ecore_List_Node *ecore_list_node_new(void);
EAPI int ecore_list_node_init(Ecore_List_Node *newNode);
/* Destroying nodes */
EAPI int ecore_list_node_destroy(Ecore_List_Node *_e_node,
Ecore_Free_Cb free_func);
EAPI int ecore_list_free_cb_set(Ecore_List *list,
Ecore_Free_Cb free_func);
typedef Ecore_List Ecore_DList;
# define ECORE_DLIST(dlist) ((Ecore_DList *)dlist)
typedef struct _ecore_dlist_node Ecore_DList_Node;
# define ECORE_DLIST_NODE(dlist) ((Ecore_DList_Node *)dlist)
struct _ecore_dlist_node
{
Ecore_List_Node single;
Ecore_DList_Node *previous;
};
/* Creating and initializing new list structures */
EAPI Ecore_DList *ecore_dlist_new(void);
EAPI int ecore_dlist_init(Ecore_DList *list);
EAPI void ecore_dlist_destroy(Ecore_DList *list);
/* Adding items to the list */
EAPI int ecore_dlist_append(Ecore_DList *_e_dlist, void *_data);
EAPI int ecore_dlist_prepend(Ecore_DList *_e_dlist, void *_data);
EAPI int ecore_dlist_insert(Ecore_DList *_e_dlist, void *_data);
EAPI int ecore_dlist_append_list(Ecore_DList *_e_dlist,
Ecore_DList *append);
EAPI int ecore_dlist_prepend_list(Ecore_DList *_e_dlist,
Ecore_DList *prepend);
/* Info about list's state */
# define ecore_dlist_first(list) ecore_list_first(list)
# define ecore_dlist_last(list) ecore_list_last(list)
EAPI void * ecore_dlist_current(Ecore_DList *list);
EAPI int ecore_dlist_index(Ecore_DList *list);
# define ecore_dlist_count(list) ecore_list_count(list)
/* Removing items from the list */
EAPI void * ecore_dlist_remove(Ecore_DList *_e_dlist);
EAPI void * ecore_dlist_first_remove(Ecore_DList *_e_dlist);
EAPI int ecore_dlist_remove_destroy(Ecore_DList *list);
EAPI void * ecore_dlist_last_remove(Ecore_DList *_e_dlist);
/* Traversing the list */
# define ecore_dlist_for_each(list, function, user_data) \
ecore_list_for_each(list, function, user_data)
EAPI void * ecore_dlist_first_goto(Ecore_DList *_e_dlist);
EAPI void * ecore_dlist_last_goto(Ecore_DList *_e_dlist);
EAPI void * ecore_dlist_index_goto(Ecore_DList *_e_dlist, int index);
EAPI void * ecore_dlist_goto(Ecore_DList *_e_dlist, void *_data);
/* Traversing the list and returning data */
EAPI void * ecore_dlist_next(Ecore_DList *list);
EAPI void * ecore_dlist_previous(Ecore_DList *list);
/* Sorting the list */
EAPI int ecore_dlist_sort(Ecore_DList *list,
Ecore_Compare_Cb compare,
char order);
EAPI int ecore_dlist_mergesort(Ecore_DList *list,
Ecore_Compare_Cb compare,
char order);
# define ecore_dlist_heapsort(list, compare, order) \
ecore_list_heapsort(list, compare, order)
EAPI void ecore_dlist_merge(Ecore_DList *list, Ecore_DList *l2,
Ecore_Compare_Cb, char order);
/* Check to see if there is any data in the list */
EAPI int ecore_dlist_empty_is(Ecore_DList *_e_dlist);
/* Remove every node in the list without free'ing it */
EAPI int ecore_dlist_clear(Ecore_DList *_e_dlist);
/* Creating and initializing list nodes */
EAPI int ecore_dlist_node_init(Ecore_DList_Node *node);
EAPI Ecore_DList_Node *ecore_dlist_node_new(void);
/* Destroying nodes */
EAPI int ecore_dlist_node_destroy(Ecore_DList_Node *node,
Ecore_Free_Cb free_func);
EAPI int ecore_dlist_free_cb_set(Ecore_DList *dlist,
Ecore_Free_Cb free_func);
/*
* Hash Table Implementation:
*
* Traditional hash table implementation. I had tried a list of tables
* approach to save on the realloc's but it ended up being much slower than
* the traditional approach.
*/
typedef struct _ecore_hash_node Ecore_Hash_Node;
# define ECORE_HASH_NODE(hash) ((Ecore_Hash_Node *)hash)
struct _ecore_hash_node
{
Ecore_Hash_Node *next; /* Pointer to the next node in the bucket list */
void *key; /* The key for the data node */
void *value; /* The value associated with this node */
};
typedef struct _ecore_hash Ecore_Hash;
# define ECORE_HASH(hash) ((Ecore_Hash *)hash)
struct _ecore_hash
{
Ecore_Hash_Node **buckets;
int size; /* An index into the table of primes to
determine size */
int nodes; /* The number of nodes currently in the hash */
int index; /* The current index into the bucket table */
Ecore_Compare_Cb compare; /* The function used to compare node values */
Ecore_Hash_Cb hash_func; /* The callback function to determine hash */
Ecore_Free_Cb free_key; /* The callback function to free key */
Ecore_Free_Cb free_value; /* The callback function to free value */
};
/* Create and initialize a hash */
EAPI Ecore_Hash *ecore_hash_new(Ecore_Hash_Cb hash_func,
Ecore_Compare_Cb compare);
EAPI int ecore_hash_init(Ecore_Hash *hash,
Ecore_Hash_Cb hash_func,
Ecore_Compare_Cb compare);
/* Functions related to freeing the data in the hash table */
EAPI int ecore_hash_free_key_cb_set(Ecore_Hash *hash,
Ecore_Free_Cb function);
EAPI int ecore_hash_free_value_cb_set(Ecore_Hash *hash,
Ecore_Free_Cb function);
EAPI void ecore_hash_destroy(Ecore_Hash *hash);
EAPI int ecore_hash_count(Ecore_Hash *hash);
EAPI int ecore_hash_for_each_node(Ecore_Hash *hash,
Ecore_For_Each for_each_func,
void *user_data);
EAPI Ecore_List *ecore_hash_keys(Ecore_Hash *hash);
/* Retrieve and store data into the hash */
EAPI void * ecore_hash_get(Ecore_Hash *hash, const void *key);
EAPI int ecore_hash_set(Ecore_Hash *hash, void *key, void *value);
EAPI int ecore_hash_hash_set(Ecore_Hash *hash, Ecore_Hash *set);
EAPI void * ecore_hash_remove(Ecore_Hash *hash, const void *key);
EAPI void * ecore_hash_find(Ecore_Hash *hash,
Ecore_Compare_Cb compare,
const void *value);
EAPI void ecore_hash_dump_graph(Ecore_Hash *hash);
EAPI void ecore_hash_dump_stats(Ecore_Hash *hash);
typedef struct _ecore_heap Ecore_Sheap;
# define ECORE_HEAP(heap) ((Ecore_Sheap *)heap)
struct _ecore_heap
{
void **data;
int size;
int space;
char order, sorted;
/* Callback for comparing node values, default is direct comparison */
Ecore_Compare_Cb compare;
/* Callback for freeing node data, default is NULL */
Ecore_Free_Cb free_func;
};
EAPI Ecore_Sheap *ecore_sheap_new(Ecore_Compare_Cb compare, int size);
EAPI void ecore_sheap_destroy(Ecore_Sheap *heap);
EAPI int ecore_sheap_init(Ecore_Sheap *heap,
Ecore_Compare_Cb compare,
int size);
EAPI int ecore_sheap_free_cb_set(Ecore_Sheap *heap,
Ecore_Free_Cb free_func);
EAPI int ecore_sheap_insert(Ecore_Sheap *heap, void *data);
EAPI void * ecore_sheap_extract(Ecore_Sheap *heap);
EAPI void * ecore_sheap_extreme(Ecore_Sheap *heap);
EAPI int ecore_sheap_change(Ecore_Sheap *heap,
void *item,
void *newval);
EAPI int ecore_sheap_compare_set(Ecore_Sheap *heap,
Ecore_Compare_Cb compare);
EAPI void ecore_sheap_order_set(Ecore_Sheap *heap, char order);
EAPI void ecore_sheap_sort(Ecore_Sheap *heap);
EAPI void * ecore_sheap_item(Ecore_Sheap *heap, int i);
typedef struct _ecore_string Ecore_String;
struct _ecore_string
{
char *string;
int references;
};
EAPI int ecore_string_init();
EAPI void ecore_string_shutdown();
EAPI const char *ecore_string_instance(const char *string);
EAPI void ecore_string_release(const char *string);
typedef struct _Ecore_Tree_Node Ecore_Tree_Node;
# define ECORE_TREE_NODE(object) ((Ecore_Tree_Node *)object)
struct _Ecore_Tree_Node
{
/* The actual data for each node */
void *key;
void *value;
/* Pointers to surrounding nodes */
Ecore_Tree_Node *parent;
Ecore_Tree_Node *left_child;
Ecore_Tree_Node *right_child;
/* Book keeping information for quicker balancing of the tree */
int max_right;
int max_left;
};
typedef struct _Ecore_Tree Ecore_Tree;
# define ECORE_TREE(object) ((Ecore_Tree *)object)
struct _Ecore_Tree
{
/* Nodes of the tree */
Ecore_Tree_Node *tree;
/* Callback for comparing node values, default is direct comparison */
Ecore_Compare_Cb compare_func;
/* Callback for freeing node data, default is NULL */
Ecore_Free_Cb free_value;
/* Callback for freeing node key, default is NULL */
Ecore_Free_Cb free_key;
};
/* Some basic tree functions */
/* Allocate and initialize a new tree */
EAPI Ecore_Tree * ecore_tree_new(Ecore_Compare_Cb compare_func);
/* Initialize a new tree */
EAPI int ecore_tree_init(Ecore_Tree *tree,
Ecore_Compare_Cb compare_func);
/* Free the tree */
EAPI int ecore_tree_destroy(Ecore_Tree *tree);
/* Check to see if the tree has any nodes in it */
EAPI int ecore_tree_empty_is(Ecore_Tree *tree);
/* Retrieve the value associated with key */
EAPI void * ecore_tree_get(Ecore_Tree *tree, const void *key);
EAPI Ecore_Tree_Node *ecore_tree_get_node(Ecore_Tree *tree, const void *key);
/* Retrieve the value of node with key greater than or equal to key */
EAPI void * ecore_tree_closest_larger_get(Ecore_Tree *tree,
const void *key);
/* Retrieve the value of node with key less than or equal to key */
EAPI void * ecore_tree_closest_smaller_get(Ecore_Tree *tree,
const void *key);
/* Set the value associated with key to value */
EAPI int ecore_tree_set(Ecore_Tree *tree, void *key, void *value);
/* Remove the key from the tree */
EAPI int ecore_tree_remove(Ecore_Tree *tree, const void *key);
/* Add a node to the tree */
EAPI int ecore_tree_node_add(Ecore_Tree *tree,
Ecore_Tree_Node *node);
/* Remove a node from the tree */
EAPI int ecore_tree_node_remove(Ecore_Tree *tree,
Ecore_Tree_Node *node);
/* For each node in the tree perform the for_each_func function */
/* For this one pass in the node */
EAPI int ecore_tree_for_each_node(Ecore_Tree *tree,
Ecore_For_Each for_each_func,
void *user_data);
/* And here pass in the node's value */
EAPI int ecore_tree_for_each_node_value(
Ecore_Tree *tree,
Ecore_For_Each
for_each_func,
void *user_data);
/* Some basic node functions */
/* Initialize a node */
EAPI int ecore_tree_node_init(Ecore_Tree_Node *new_node);
/* Allocate and initialize a new node */
EAPI Ecore_Tree_Node *ecore_tree_node_new(void);
/* Free the desired node */
EAPI int ecore_tree_node_destroy(Ecore_Tree_Node *node,
Ecore_Free_Cb free_value,
Ecore_Free_Cb free_key);
/* Set the node's key to key */
EAPI int ecore_tree_node_key_set(Ecore_Tree_Node *node, void *key);
/* Retrieve the key in node */
EAPI void * ecore_tree_node_key_get(Ecore_Tree_Node *node);
/* Set the node's value to value */
EAPI int ecore_tree_node_value_set(Ecore_Tree_Node *node,
void *value);
/* Retrieve the value in node */
EAPI void * ecore_tree_node_value_get(Ecore_Tree_Node *node);
/* Add a function to free the data stored in nodes */
EAPI int ecore_tree_free_value_cb_set(Ecore_Tree *tree,
Ecore_Free_Cb free_value);
/* Add a function to free the keys stored in nodes */
EAPI int ecore_tree_free_key_cb_set(Ecore_Tree *tree,
Ecore_Free_Cb free_key);
EAPI Ecore_Strbuf * ecore_strbuf_new(void);
EAPI void ecore_strbuf_free(Ecore_Strbuf *buf);
EAPI void ecore_strbuf_append(Ecore_Strbuf *buf, const char *str);
EAPI void ecore_strbuf_append_char(Ecore_Strbuf *buf, char c);
EAPI void ecore_strbuf_insert(Ecore_Strbuf *buf, const char *str,
size_t pos);
# define ecore_strbuf_prepend(buf, str) ecore_strbuf_insert(buf, str, 0)
EAPI const char * ecore_strbuf_string_get(Ecore_Strbuf *buf);
EAPI size_t ecore_strbuf_length_get(Ecore_Strbuf *buf);
EAPI int ecore_strbuf_replace(Ecore_Strbuf *buf, const char *str,
const char *with, unsigned int n);
# define ecore_strbuf_replace_first(buf, str, with) \
ecore_strbuf_replace(buf, str, with, 1)
EAPI int ecore_strbuf_replace_all(Ecore_Strbuf *buf,
const char *str,
const char *with);
extern int ecore_str_compare(const void *key1, const void *key2);
extern int ecore_direct_compare(const void *key1, const void *key2);
extern unsigned int ecore_str_hash(const void *key);
#ifdef __cplusplus
}
#endif
#endif /* _ECORE_DATA_H */

View File

@ -0,0 +1,195 @@
#ifndef _EVAS_DATA_H
#define _EVAS_DATA_H
#ifdef EAPI
# undef EAPI
#endif
#ifdef _WIN32
# ifdef EFL_EVAS_BUILD
# ifdef DLL_EXPORT
# define EAPI __declspec(dllexport)
# else
# define EAPI
# endif /* ! DLL_EXPORT */
# else
# define EAPI __declspec(dllimport)
# endif /* ! EFL_EVAS_BUILD */
#else
# ifdef __GNUC__
# if __GNUC__ >= 4
# define EAPI __attribute__ ((visibility("default")))
# else
# define EAPI
# endif
# else
# define EAPI
# endif
#endif /* ! _WIN32 */
/**
* @file
* @brief These routines are used for Evas data types.
*/
typedef unsigned char Evas_Bool;
typedef struct _Evas_Array_Hash Evas_Array_Hash;
typedef struct _Evas_Hash Evas_Hash; /**< A Hash table handle */
typedef struct _Evas_List Evas_List; /**< A generic linked list node handle */
typedef struct _Evas_Object_List Evas_Object_List;
struct _Evas_Hash
{
int population;
Evas_Object_List *buckets[256];
};
struct _Evas_List /** A linked list node */
{
void *data; /**< Pointer to list element payload */
Evas_List *next; /**< Next member in the list */
Evas_List *prev; /**< Previous member in the list */
struct _Evas_List_Accounting *accounting; /**< Private list accounting info - don't touch */
};
struct _Evas_Object_List
{
Evas_Object_List *next, *prev;
Evas_Object_List *last;
};
#ifdef __cplusplus
extern "C" {
#endif
/*
* Evas Array Hash functions
*/
EAPI Evas_Array_Hash *evas_array_hash_new (void);
EAPI void evas_array_hash_free (Evas_Array_Hash *hash);
EAPI void evas_array_hash_add (Evas_Array_Hash *hash,
int key,
int data);
EAPI int evas_array_hash_search (Evas_Array_Hash *hash,
int key);
/*
* Evas Hash functions
*/
/* FIXME: add:
* api to add find, del members by data, size not just string and also
* provide hash generation functions settable by the app
*
* do we really need this? hmmm - let me think... there may be a better way
*/
EAPI Evas_Hash *evas_hash_add (Evas_Hash *hash,
const char *key,
const void *data);
EAPI Evas_Hash *evas_hash_direct_add (Evas_Hash *hash,
const char *key,
const void *data);
EAPI Evas_Hash *evas_hash_del (Evas_Hash *hash,
const char *key,
const void *data);
EAPI void * evas_hash_find (const Evas_Hash *hash,
const char *key);
EAPI void * evas_hash_modify (Evas_Hash *hash,
const char *key,
const void *data);
EAPI int evas_hash_size (const Evas_Hash *hash);
EAPI void evas_hash_free (Evas_Hash *hash);
EAPI void evas_hash_foreach (const Evas_Hash *hash,
Evas_Bool (*func)(
const Evas_Hash *hash,
const char *
key,
void *data,
void *fdata),
const void *fdata);
EAPI int evas_hash_alloc_error (void);
/*
* Evas List functions
*/
EAPI Evas_List *evas_list_append (Evas_List *list,
const void *data);
EAPI Evas_List *evas_list_prepend (Evas_List *list,
const void *data);
EAPI Evas_List *evas_list_append_relative (Evas_List *list,
const void *data,
const void *relative);
EAPI Evas_List *evas_list_append_relative_list (Evas_List *list,
const void *data,
Evas_List *relative);
EAPI Evas_List *evas_list_prepend_relative (Evas_List *list,
const void *data,
const void *relative);
EAPI Evas_List *evas_list_prepend_relative_list (Evas_List *list,
const void *data,
Evas_List *relative);
EAPI Evas_List *evas_list_remove (Evas_List *list,
const void *data);
EAPI Evas_List *evas_list_remove_list (Evas_List *list,
Evas_List *remove_list);
EAPI Evas_List *evas_list_promote_list (Evas_List *list,
Evas_List *move_list);
EAPI void * evas_list_find (const Evas_List *list,
const void *data);
EAPI Evas_List *evas_list_find_list (const Evas_List *list,
const void *data);
EAPI Evas_List *evas_list_free (Evas_List *list);
EAPI Evas_List *evas_list_last (const Evas_List *list);
EAPI Evas_List *evas_list_next (const Evas_List *list);
EAPI Evas_List *evas_list_prev (const Evas_List *list);
EAPI void * evas_list_data (const Evas_List *list);
EAPI int evas_list_count (const Evas_List *list);
EAPI void * evas_list_nth (const Evas_List *list, int n);
EAPI Evas_List *evas_list_nth_list (const Evas_List *list, int n);
EAPI Evas_List *evas_list_reverse (Evas_List *list);
EAPI Evas_List *evas_list_sort (Evas_List *list,
int size,
int (*func)(void *,void *));
EAPI int evas_list_alloc_error (void);
/*
* Evas Object List functions
*/
EAPI void * evas_object_list_append (void *in_list,
void *in_item);
EAPI void * evas_object_list_prepend (void *in_list,
void *in_item);
EAPI void * evas_object_list_append_relative (void *in_list,
void *in_item,
void *in_relative);
EAPI void * evas_object_list_prepend_relative (void *in_list,
void *in_item,
void *in_relative);
EAPI void * evas_object_list_remove (void *in_list,
void *in_item);
EAPI void * evas_object_list_find (void *in_list,
void *in_item);
/*
* Evas Stringshare functions
*/
EAPI void evas_stringshare_init (void); /* not implemented */
EAPI void evas_stringshare_shutdown (void); /* not implemented */
EAPI const char *evas_stringshare_add (const char *str);
EAPI void evas_stringshare_del (const char *str);
#ifdef __cplusplus
}
#endif
#endif /* _EVAS_DATA_H */

View File

@ -0,0 +1,120 @@
MAINTAINERCLEANFILES = Makefile.in
benchdir = $(bindir)
AM_CPPFLAGS = \
-I$(top_srcdir)/src/lib \
-I$(top_srcdir)/src/include \
-I$(top_builddir)/src/include \
-I$(top_builddir)/src/lib \
-DPACKAGE_BIN_DIR=\"$(bindir)\" \
-DPACKAGE_LIB_DIR=\"$(libdir)\" \
-DPACKAGE_DATA_DIR=\"$(datadir)/$(PACKAGE)\" \
-DPACKAGE_BUILD_DIR=\"`pwd`/$(top_builddir)\" \
@CHECK_CFLAGS@ \
@GLIB_CFLAGS@
if EINA_HAVE_GLIB
AM_CPPFLAGS += -DEINA_BENCH_HAVE_GLIB
endif
if EINA_ENABLE_BENCHMARK_E17
AM_CPPFLAGS += -DEINA_ENABLE_BENCH_E17
endif
if EFL_ENABLE_TESTS
check_PROGRAMS = eina_suite
eina_suite_SOURCES = \
eina_suite.c \
eina_test_fp.c \
eina_test_stringshare.c \
eina_test_ustringshare.c\
eina_test_ustr.c \
eina_test_binshare.c \
eina_test_array.c \
eina_test_error.c \
eina_test_sched.c \
eina_test_log.c \
eina_test_magic.c \
eina_test_inlist.c \
eina_test_main.c \
eina_test_counter.c \
eina_test_lalloc.c \
eina_test_hash.c \
eina_test_iterator.c \
eina_test_accessor.c \
eina_test_module.c \
eina_test_convert.c \
eina_test_rbtree.c \
eina_test_file.c \
eina_test_benchmark.c \
eina_test_mempool.c \
eina_test_rectangle.c \
eina_test_list.c \
eina_test_matrixsparse.c \
eina_test_tiler.c \
eina_test_strbuf.c \
eina_test_str.c \
eina_test_quadtree.c
eina_suite_LDADD = @CHECK_LIBS@ $(top_builddir)/src/lib/libeina.la -lm
module_dummydir = $(libdir)/eina/test
module_dummy_LTLIBRARIES = module_dummy.la
module_dummy_la_SOURCES = \
eina_test_module_dummy.c
module_dummy_la_CPPFLAGS = \
-I$(top_srcdir)/src/lib \
-I$(top_srcdir)/src/include \
-I$(top_builddir)/src/include \
-I$(top_builddir)/src/lib \
@EFL_EINA_BUILD@
module_dummy_la_LIBADD = $(top_builddir)/src/lib/libeina.la @EINA_LIBS@
module_dummy_la_LDFLAGS = -no-undefined @lt_enable_auto_import@ -module -avoid-version
module_dummy_la_LIBTOOLFLAGS = --tag=disable-static
endif
if EFL_ENABLE_BENCHMARK
bench_PROGRAMS = eina_bench
eina_bench_SOURCES = \
eina_bench.c \
eina_bench_sort.c \
eina_bench_hash.c \
eina_bench_stringshare.c \
eina_bench_convert.c \
eina_bench_mempool.c \
eina_bench_stringshare_e17.c \
eina_bench_array.c \
eina_bench_rectangle_pool.c \
ecore_list.c \
ecore_strings.c \
ecore_hash.c \
ecore_sheap.c \
evas_hash.c \
evas_list.c \
evas_mempool.c \
evas_object_list.c \
evas_stringshare.c \
eina_bench_quad.c
eina_bench_LDADD = @GLIB_LIBS@ $(top_builddir)/src/lib/libeina.la
endif
EXTRA_DIST = eina_bench.h \
eina_suite.h \
Ecore_Data.h \
Evas_Data.h \
evas_mempool.h \
strlog

View File

@ -0,0 +1,949 @@
#ifdef HAVE_CONFIG_H
# include <config.h>
#endif
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include "Ecore_Data.h"
#define PRIME_TABLE_MAX 21
#define PRIME_MIN 17
#define PRIME_MAX 16777213
#define ECORE_HASH_CHAIN_MAX 3
#define ECORE_COMPUTE_HASH(hash, key) hash->hash_func(key) % \
ecore_prime_table[hash->size];
#define ECORE_HASH_INCREASE(hash) ((hash && ecore_prime_table[hash->size] < \
PRIME_MAX) ? \
(hash->nodes / \
ecore_prime_table[hash->size]) > \
ECORE_HASH_CHAIN_MAX : FALSE)
#define ECORE_HASH_REDUCE(hash) ((hash && ecore_prime_table[hash->size] > \
PRIME_MIN) ? \
(double)hash->nodes / \
(double)ecore_prime_table[hash->size - 1] \
< ((double)ECORE_HASH_CHAIN_MAX * \
0.375) : FALSE)
static const unsigned int ecore_prime_table[] =
{
17, 31, 61, 127, 257, 509, 1021,
2053, 4093, 8191, 16381, 32771, 65537, 131071, 262147, 524287, 1048573,
2097143, 4194301, 8388617, 16777213
};
/* Private hash manipulation functions */
static int _ecore_hash_node_add(Ecore_Hash *hash,
Ecore_Hash_Node *node);
static Ecore_Hash_Node * _ecore_hash_node_get(Ecore_Hash *hash,
const void *key);
static int _ecore_hash_increase(Ecore_Hash *hash);
static int _ecore_hash_decrease(Ecore_Hash *hash);
static inline int _ecore_hash_rehash(Ecore_Hash *hash,
Ecore_Hash_Node **old_table,
int old_size);
static int _ecore_hash_bucket_destroy(Ecore_Hash_Node *list,
Ecore_Free_Cb keyd,
Ecore_Free_Cb valued);
static inline Ecore_Hash_Node *_ecore_hash_bucket_get(Ecore_Hash *hash,
Ecore_Hash_Node *bucket,
const void *key);
static Ecore_Hash_Node * _ecore_hash_node_new(void *key, void *value);
static int _ecore_hash_node_init(Ecore_Hash_Node *node,
void *key,
void *value);
static int _ecore_hash_node_destroy(Ecore_Hash_Node *node,
Ecore_Free_Cb keyd,
Ecore_Free_Cb valued);
/**
* @defgroup Ecore_Data_Hash_ADT_Creation_Group Hash Creation Functions
*
* Functions that create hash tables.
*/
/**
* Creates and initializes a new hash
* @param hash_func The function for determining hash position.
* @param compare The function for comparing node keys.
* @return @c NULL on error, a new hash on success.
* @ingroup Ecore_Data_Hash_ADT_Creation_Group
*/
EAPI Ecore_Hash *
ecore_hash_new(Ecore_Hash_Cb hash_func, Ecore_Compare_Cb compare)
{
Ecore_Hash *new_hash = (Ecore_Hash *)malloc(sizeof(Ecore_Hash));
if (!new_hash)
return NULL;
if (!ecore_hash_init(new_hash, hash_func, compare))
{
FREE(new_hash);
return NULL;
}
return new_hash;
}
/**
* Initializes the given hash.
* @param hash The given hash.
* @param hash_func The function used for hashing node keys.
* @param compare The function used for comparing node keys.
* @return @c TRUE on success, @c FALSE on an error.
* @ingroup Ecore_Data_Hash_ADT_Creation_Group
*/
EAPI int
ecore_hash_init(Ecore_Hash *hash,
Ecore_Hash_Cb hash_func,
Ecore_Compare_Cb compare)
{
CHECK_PARAM_POINTER_RETURN("hash", hash, FALSE);
memset(hash, 0, sizeof(Ecore_Hash));
hash->hash_func = hash_func;
hash->compare = compare;
hash->buckets = (Ecore_Hash_Node **)calloc(ecore_prime_table[0],
sizeof(Ecore_Hash_Node *));
return TRUE;
}
/**
* @defgroup Ecore_Data_Hash_ADT_Destruction_Group Hash Destruction Functions
*
* Functions that destroy hash tables and their contents.
*/
/**
* Sets the function to destroy the keys of the given hash.
* @param hash The given hash.
* @param function The function used to free the node keys. NULL is a
* valid value and means that no function will be called.
* @return @c TRUE on success, @c FALSE on error.
* @ingroup Ecore_Data_Hash_ADT_Destruction_Group
*/
EAPI int
ecore_hash_free_key_cb_set(Ecore_Hash *hash, Ecore_Free_Cb function)
{
CHECK_PARAM_POINTER_RETURN("hash", hash, FALSE);
hash->free_key = function;
return TRUE;
}
/**
* Sets the function to destroy the values in the given hash.
* @param hash The given hash.
* @param function The function that will free the node values. NULL is a
* valid value and means that no function will be called.
* @return @c TRUE on success, @c FALSE on error
* @ingroup Ecore_Data_Hash_ADT_Destruction_Group
*/
EAPI int
ecore_hash_free_value_cb_set(Ecore_Hash *hash, Ecore_Free_Cb function)
{
CHECK_PARAM_POINTER_RETURN("hash", hash, FALSE);
hash->free_value = function;
return TRUE;
}
/**
* @defgroup Ecore_Data_Hash_ADT_Data_Group Hash Data Functions
*
* Functions that set, access and delete values from the hash tables.
*/
/**
* Sets a key-value pair in the given hash table.
* @param hash The given hash table.
* @param key The key.
* @param value The value.
* @return @c TRUE if successful, @c FALSE if not.
* @ingroup Ecore_Data_Hash_ADT_Data_Group
*/
EAPI int
ecore_hash_set(Ecore_Hash *hash, void *key, void *value)
{
int ret = FALSE;
Ecore_Hash_Node *node;
CHECK_PARAM_POINTER_RETURN("hash", hash, FALSE);
node = _ecore_hash_node_get(hash, key);
if (node)
{
if (hash->free_key)
hash->free_key(key);
if (node->value && hash->free_value)
hash->free_value(node->value);
node->value = value;
ret = TRUE;
}
else
{
node = _ecore_hash_node_new(key, value);
if (node)
ret = _ecore_hash_node_add(hash, node);
}
return ret;
}
/**
* Sets all key-value pairs from set in the given hash table.
* @param hash The given hash table.
* @param set The hash table to import.
* @return @c TRUE if successful, @c FALSE if not.
* @ingroup Ecore_Data_Hash_ADT_Data_Group
*/
EAPI int
ecore_hash_hash_set(Ecore_Hash *hash, Ecore_Hash *set)
{
unsigned int i;
Ecore_Hash_Node *node, *old;
CHECK_PARAM_POINTER_RETURN("hash", hash, FALSE);
CHECK_PARAM_POINTER_RETURN("set", set, FALSE);
for (i = 0; i < ecore_prime_table[set->size]; i++)
{
/* Hash into a new list to avoid loops of rehashing the same nodes */
while ((old = set->buckets[i]))
{
set->buckets[i] = old->next;
old->next = NULL;
node = _ecore_hash_node_get(hash, old->key);
if (node)
{
/* This key already exists. Delete the old and add the new
* value */
if (hash->free_key)
hash->free_key(node->key);
if (hash->free_value)
hash->free_key(node->value);
node->key = old->key;
node->value = old->value;
free(old);
}
else
_ecore_hash_node_add(hash, old);
}
}
FREE(set->buckets);
ecore_hash_init(set, set->hash_func, set->compare);
return TRUE;
}
/**
* Frees the hash table and the data contained inside it.
* @param hash The hash table to destroy.
* @return @c TRUE on success, @c FALSE on error.
* @ingroup Ecore_Data_Hash_ADT_Destruction_Group
*/
EAPI void
ecore_hash_destroy(Ecore_Hash *hash)
{
unsigned int i = 0;
CHECK_PARAM_POINTER("hash", hash);
if (hash->buckets)
{
while (i < ecore_prime_table[hash->size])
{
if (hash->buckets[i])
{
Ecore_Hash_Node *bucket;
/*
* Remove the bucket list to avoid possible recursion
* on the free callbacks.
*/
bucket = hash->buckets[i];
hash->buckets[i] = NULL;
_ecore_hash_bucket_destroy(bucket,
hash->free_key,
hash->free_value);
}
i++;
}
FREE(hash->buckets);
}
FREE(hash);
return;
}
/**
* @defgroup Ecore_Data_Hash_ADT_Traverse_Group Hash Traverse Functions
*
* Functions that iterate through hash tables.
*/
/**
* Counts the number of nodes in a hash table.
* @param hash The hash table to count current nodes.
* @return The number of nodes in the hash.
* @ingroup Ecore_Data_Hash_ADT_Destruction_Group
*/
EAPI int
ecore_hash_count(Ecore_Hash *hash)
{
CHECK_PARAM_POINTER_RETURN("hash", hash, 0);
return hash->nodes;
}
/**
* Runs the @p for_each_func function on each entry in the given hash.
* @param hash The given hash.
* @param for_each_func The function that each entry is passed to.
* @param user_data a pointer passed to calls of for_each_func
* @return TRUE on success, FALSE otherwise.
* @ingroup Ecore_Data_Hash_ADT_Traverse_Group
*/
EAPI int
ecore_hash_for_each_node(Ecore_Hash *hash,
Ecore_For_Each for_each_func,
void *user_data)
{
unsigned int i = 0;
CHECK_PARAM_POINTER_RETURN("hash", hash, FALSE);
CHECK_PARAM_POINTER_RETURN("for_each_func", for_each_func, FALSE);
while (i < ecore_prime_table[hash->size])
{
if (hash->buckets[i])
{
Ecore_Hash_Node *node;
for (node = hash->buckets[i]; node; node = node->next)
{
for_each_func(node, user_data);
}
}
i++;
}
return TRUE;
}
/**
* Retrieves an ecore_list of all keys in the given hash.
* @param hash The given hash.
* @return new ecore_list on success, NULL otherwise
* @ingroup Ecore_Data_Hash_ADT_Traverse_Group
*/
EAPI Ecore_List *
ecore_hash_keys(Ecore_Hash *hash)
{
unsigned int i = 0;
Ecore_List *keys;
CHECK_PARAM_POINTER_RETURN("hash", hash, NULL);
keys = ecore_list_new();
while (i < ecore_prime_table[hash->size])
{
if (hash->buckets[i])
{
Ecore_Hash_Node *node;
for (node = hash->buckets[i]; node; node = node->next)
{
ecore_list_append(keys, node->key);
}
}
i++;
}
ecore_list_first_goto(keys);
return keys;
}
/**
* Prints the distribution of the given hash table for graphing.
* @param hash The given hash table.
*/
EAPI void
ecore_hash_dump_graph(Ecore_Hash *hash)
{
unsigned int i;
for (i = 0; i < ecore_prime_table[hash->size]; i++)
if (hash->buckets[i])
{
int n = 0;
Ecore_Hash_Node *node;
for (node = hash->buckets[i]; node; node = node->next)
n++;
printf("%d\t%u", i, n);
}
else
printf("%d\t0", i);
}
/**
* Prints the distribution of the given hash table for graphing.
* @param hash The given hash table.
*/
EAPI void
ecore_hash_dump_stats(Ecore_Hash *hash)
{
unsigned int i;
double variance, sum_n_2 = 0, sum_n = 0;
for (i = 0; i < ecore_prime_table[hash->size]; i++)
{
if (hash->buckets[i])
{
int n = 0;
Ecore_Hash_Node *node;
for (node = hash->buckets[i]; node; node = node->next)
n++;
sum_n_2 += ((double)n * (double)n);
sum_n += (double)n;
}
}
variance = (sum_n_2 - ((sum_n * sum_n) / (double)i)) / (double)i;
printf("Average length: %f\n\tvariance^2: %f", (sum_n / (double)i),
variance);
}
static int
_ecore_hash_bucket_destroy(Ecore_Hash_Node *list,
Ecore_Free_Cb keyd,
Ecore_Free_Cb valued)
{
Ecore_Hash_Node *node;
CHECK_PARAM_POINTER_RETURN("list", list, FALSE);
for (node = list; node; node = list)
{
list = list->next;
_ecore_hash_node_destroy(node, keyd, valued);
}
return TRUE;
}
/*
* @brief Add the node to the hash table
* @param hash: the hash table to add the key
* @param node: the node to add to the hash table
* @return Returns FALSE on error, TRUE on success
*/
static int
_ecore_hash_node_add(Ecore_Hash *hash, Ecore_Hash_Node *node)
{
unsigned long hash_val;
CHECK_PARAM_POINTER_RETURN("hash", hash, FALSE);
CHECK_PARAM_POINTER_RETURN("node", node, FALSE);
/* Check to see if the hash needs to be resized */
if (ECORE_HASH_INCREASE(hash))
_ecore_hash_increase(hash);
/* Compute the position in the table */
if (!hash->hash_func)
hash_val = (unsigned long)node->key % ecore_prime_table[hash->size];
else
hash_val = ECORE_COMPUTE_HASH(hash, node->key);
/* Prepend the node to the list at the index position */
node->next