diff options
author | Alex Auvolat <alex.auvolat@ens.fr> | 2015-02-09 17:56:59 +0100 |
---|---|---|
committer | Alex Auvolat <alex.auvolat@ens.fr> | 2015-02-09 17:56:59 +0100 |
commit | 002a1b035e2464c11b17f1bfd3835deccef7652a (patch) | |
tree | 640baf35dce60566a8f14eec54212af848e5ad71 /src/common/include | |
parent | f2c51bc81d2aa618b29ddbeaae5ac1c5308821f0 (diff) | |
download | kogata-002a1b035e2464c11b17f1bfd3835deccef7652a.tar.gz kogata-002a1b035e2464c11b17f1bfd3835deccef7652a.zip |
Change readme, remove unused code, changed hashtbl to add key freeing function.
Diffstat (limited to 'src/common/include')
-rw-r--r-- | src/common/include/buffer.h | 41 | ||||
-rw-r--r-- | src/common/include/hashtbl.h | 9 | ||||
-rw-r--r-- | src/common/include/string.h | 2 |
3 files changed, 8 insertions, 44 deletions
diff --git a/src/common/include/buffer.h b/src/common/include/buffer.h deleted file mode 100644 index 0d6cfbf..0000000 --- a/src/common/include/buffer.h +++ /dev/null @@ -1,41 +0,0 @@ -#pragma once - -#include <stdint.h> -#include <stddef.h> -#include <stdbool.h> - -// The buffer_t type is a simple reference-counted buffer type -// enabling the creation, sharing, slicing and concatenation of buffers -// without having to copy everything each time - -// Buffers are always allocated on the core kernel heap (kmalloc/kfree) - -// Once a buffer is allocated, its contents is immutable - -// Encoding and decoding functions for buffer contents are provided in -// a separate file (encode.h) - -struct buffer; -typedef struct buffer buffer_t; - -void buffer_ref(buffer_t*); // increase reference counter -void buffer_unref(buffer_t*); // decrease reference counter - -size_t buffer_len(buffer_t* buf); -size_t read_buffer(buffer_t* buf, char* to, size_t begin, size_t n); // returns num of bytes read - -buffer_t* buffer_from_bytes(const char* data, size_t n); // bytes are COPIED -buffer_t* buffer_from_bytes_nocopy(const char* data, size_t n, bool own_bytes); // bytes are NOT COPIED - -// these functions GIVE the buffer in order to create the new buffer, ie they do not increase RC -// the buffer is NOT GIVED if the new buffer could not be created (ie retval == 0) -buffer_t* buffer_slice(buffer_t* b, size_t begin, size_t n); -buffer_t* buffer_concat(buffer_t* a, buffer_t* b); - -// these functions KEEP a reference on the buffer (ie RC is incremented) -// the RC is NOT INCREMENTED if the new buffer cannot be created -buffer_t* buffer_slice_k(buffer_t* b, size_t begin, size_t n); -buffer_t* buffer_concat_k(buffer_t* a, buffer_t* b); - - -/* vim: set ts=4 sw=4 tw=0 noet :*/ diff --git a/src/common/include/hashtbl.h b/src/common/include/hashtbl.h index 16dfefb..3b5a44d 100644 --- a/src/common/include/hashtbl.h +++ b/src/common/include/hashtbl.h @@ -8,8 +8,10 @@ // Supports adding, seeking, removing // When adding a binding to the table, the previous binding for same key (if exists) is removed -// TODO : possibility to allocate the hashtbl structure on any heap -// (currently uses kmalloc/kfree) +// The hashtbl is allocated with malloc/free +// The keys are not copied in any way by the hashtbl, but there might still be something +// to free, so the create_hashtbl function is given a key freeing function, usually +// null when no freeing is required, or the standard free function. struct hashtbl; typedef struct hashtbl hashtbl_t; @@ -17,8 +19,9 @@ typedef struct hashtbl hashtbl_t; typedef size_t hash_t; typedef hash_t (*hash_fun_t)(const void*); typedef bool (*key_eq_fun_t)(const void*, const void*); +typedef void (*key_free_fun_t)(void*); -hashtbl_t* create_hashtbl(key_eq_fun_t ef, hash_fun_t hf, size_t initial_size); // 0 -> default size +hashtbl_t* create_hashtbl(key_eq_fun_t ef, hash_fun_t hf, key_free_fun_t ff, size_t initial_size); // 0 -> default size void delete_hashtbl(hashtbl_t* ht); int hashtbl_add(hashtbl_t* ht, void* key, void* v); // non-null on error (OOM for instance) diff --git a/src/common/include/string.h b/src/common/include/string.h index 682b25a..a7a5253 100644 --- a/src/common/include/string.h +++ b/src/common/include/string.h @@ -14,4 +14,6 @@ char *strcpy(char *dest, const char *src); char *strcat(char *dest, const char *src); int strcmp(const char *s1, const char *s2); +char *strdup(const char* str); + /* vim: set ts=4 sw=4 tw=0 noet :*/ |