Add Development Guide to Project and implement kv_store.h.
This commit is contained in:
@@ -0,0 +1,91 @@
|
||||
#ifndef KV_STORE_H
|
||||
#define KV_STORE_H
|
||||
|
||||
/*
|
||||
* Key/Value structure containing a key and associated value.
|
||||
*/
|
||||
typedef struct {
|
||||
char *key;
|
||||
char *value;
|
||||
} kv_store_entry_t;
|
||||
|
||||
/*
|
||||
* Colleciton structure containing the entries of a Key/Value store.
|
||||
*/
|
||||
typedef struct {
|
||||
kv_store_entry_t *entries;
|
||||
int length; // Current length of store
|
||||
int capacity; // Capacity of store
|
||||
} kv_store_t;
|
||||
|
||||
/*
|
||||
* kv_store_entry_init - Initialize a Key/Value Store Entry
|
||||
* @key: Key for the entry
|
||||
* @value: Value for the entry
|
||||
*
|
||||
* Returns: Pointer to newly allocated kv_store_entry_t, or NULL on failure.
|
||||
* Caller must free the returned pointer.
|
||||
*/
|
||||
kv_store_entry_t *kv_store_entry_init(const char *key, const char *value);
|
||||
|
||||
/*
|
||||
* kv_store_entry_copy - Copy a Key/Value Store Entry
|
||||
* @entry: Entry to copy
|
||||
*
|
||||
* Returns: Pointer to newly allocated copy of kv_store_entry_t, or NULL on
|
||||
* failure. Caller must free the returned pointer.
|
||||
*/
|
||||
kv_store_entry_t *kv_store_entry_copy(const kv_store_entry_t *entry);
|
||||
|
||||
/*
|
||||
* kv_store_entry_free - Free a Key/Value Store Entry
|
||||
* @entry: Entry to free
|
||||
*/
|
||||
void kv_store_entry_free(kv_store_entry_t *entry);
|
||||
|
||||
/*
|
||||
* kv_store_init - Initialize a Key/Value Store
|
||||
* @capacity: Initial capacity of the store
|
||||
*
|
||||
* Returns: Pointer to newly allocated kv_store_t, or NULL on failure. Caller
|
||||
* must free the returned pointer.
|
||||
*/
|
||||
kv_store_t *kv_store_init(int capacity);
|
||||
|
||||
/*
|
||||
* kv_store_free - Free a Key/Value Store
|
||||
* @store: Store to free
|
||||
*/
|
||||
void kv_store_free(kv_store_t *store);
|
||||
|
||||
/*
|
||||
* kv_store_get_entry - Get Key/Value Store Entry from Store
|
||||
* @store: KV Store
|
||||
* @key: Key to get from store.
|
||||
*
|
||||
* Returns: Pointer to newly allocated copy of the entry, or NULL if not found
|
||||
* or on failure. Caller must free the returned pointer.
|
||||
*/
|
||||
kv_store_entry_t *kv_store_get_entry(const kv_store_t *store, const char *key);
|
||||
|
||||
/*
|
||||
* kv_store_set_entry - Set Key/Value Store Entry to Store
|
||||
* @store: KV Store
|
||||
* @key: Key to set or update in store.
|
||||
*
|
||||
* Returns: 1 if value is updated, 0 if the value was added, or -1 on
|
||||
* failure.
|
||||
*/
|
||||
int kv_store_set_entry(kv_store_t *const store, const kv_store_entry_t *entry);
|
||||
|
||||
/*
|
||||
* kv_store_delete_entry - Delete Key/Value Store Entry from Store
|
||||
* @store: KV Store
|
||||
* @key: Key to delete from store.
|
||||
*
|
||||
* Returns: 1 if the value was deleted, 0 if the value was not found, or -1
|
||||
* on failure.
|
||||
*/
|
||||
int kv_store_delete_entry(kv_store_t *const store, const char *key);
|
||||
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user