Commit b504a051 authored by Matthieu Dorier's avatar Matthieu Dorier

added implementation of omap_iterator

parent b70270ff
...@@ -108,7 +108,7 @@ typedef void *mobject_store_ioctx_t; ...@@ -108,7 +108,7 @@ typedef void *mobject_store_ioctx_t;
* mobject_store_read_op_omap_get_vals_by_keys(), mobject_store_omap_get_next(), and * mobject_store_read_op_omap_get_vals_by_keys(), mobject_store_omap_get_next(), and
* mobject_store_omap_get_end(). * mobject_store_omap_get_end().
*/ */
typedef void *mobject_store_omap_iter_t; typedef struct mobject_store_omap_iter *mobject_store_omap_iter_t;
/** /**
* @typedef mobject_store_write_op_t * @typedef mobject_store_write_op_t
......
...@@ -8,7 +8,8 @@ src_libmobject_store_la_SOURCES = \ ...@@ -8,7 +8,8 @@ src_libmobject_store_la_SOURCES = \
src/prepare-write-op.c \ src/prepare-write-op.c \
src/prepare-read-op.c \ src/prepare-read-op.c \
src/write-op-visitor.c \ src/write-op-visitor.c \
src/read-op-visitor.c src/read-op-visitor.c \
src/omap-iter-impl.c
noinst_HEADERS += \ noinst_HEADERS += \
src/log.h \ src/log.h \
...@@ -24,4 +25,5 @@ noinst_HEADERS += \ ...@@ -24,4 +25,5 @@ noinst_HEADERS += \
src/prepare-read-op.h \ src/prepare-read-op.h \
src/write-op-visitor.h \ src/write-op-visitor.h \
src/read-op-visitor.h \ src/read-op-visitor.h \
src/buffer-union.h src/buffer-union.h \
src/omap-iter-impl.h
/*
* (C) 2017 The University of Chicago
*
* See COPYRIGHT in top-level directory.
*/
#include <stdlib.h>
#include <string.h>
#include "utlist.h"
#include "libmobject-store.h"
#include "omap-iter-impl.h"
void omap_iter_create(mobject_store_omap_iter_t* iter)
{
*iter = (mobject_store_omap_iter_t)calloc(1, sizeof(**iter));
}
void omap_iter_free(mobject_store_omap_iter_t iter)
{
omap_iter_node_t elt, tmp;
DL_FOREACH_SAFE(iter->head, elt, tmp) {
DL_DELETE(iter->head, elt);
free((void*)(elt->key));
free((void*)(elt->value));
free((void*)(elt));
}
free(iter);
}
void omap_iter_append(mobject_store_omap_iter_t iter,
const char* key, const char* val,
size_t val_size)
{
omap_iter_node_t item = (omap_iter_node_t)calloc(1, sizeof(*item));
item->key = strdup(key);
item->value_size = val_size;
item->value = (char*)malloc(val_size);
memcpy(item->value, val, val_size);
DL_APPEND(iter->head, item);
if(iter->current == NULL)
iter->current = iter->head;
}
int mobject_store_omap_get_next(mobject_store_omap_iter_t iter,
char **key,
char **val,
size_t *len)
{
if(iter->current == NULL) return -1;
*key = iter->current->key;
*val = iter->current->value;
*len = iter->current->value_size;
iter->current = iter->current->next;
return 0;
}
void mobject_store_omap_get_end(mobject_store_omap_iter_t iter)
{
omap_iter_free(iter);
}
/*
* (C) 2017 The University of Chicago
*
* See COPYRIGHT in top-level directory.
*/
#ifndef __MOBJECT_OMAP_ITER_H
#define __MOBJECT_OMAP_ITER_H
#include "libmobject-store.h"
#define OMAP_ITER_OWNS_KEY 0x1
#define OMAP_ITER_OWNS_VALUE 0x2
typedef struct omap_iter_node* omap_iter_node_t;
struct omap_iter_node {
char* key;
char* value;
size_t value_size;
omap_iter_node_t prev, next;
};
struct mobject_store_omap_iter {
omap_iter_node_t head;
omap_iter_node_t current;
};
void omap_iter_create(mobject_store_omap_iter_t* iter);
void omap_iter_free(mobject_store_omap_iter_t iter);
void omap_iter_append(mobject_store_omap_iter_t iter,
const char* key, const char* val,
size_t val_size);
#endif
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment