mirror of
https://github.com/johnkerl/miller.git
synced 2026-01-23 02:14:13 +00:00
moosvar iterate
This commit is contained in:
parent
9261c798fc
commit
69b6f59e71
9 changed files with 141 additions and 9 deletions
2
.gitignore
vendored
2
.gitignore
vendored
|
|
@ -12,6 +12,7 @@ test-peek-file-reader
|
|||
test-parse-trie
|
||||
test-lrec
|
||||
test-multiple-containers
|
||||
test-mlhmmv
|
||||
test-lrec-evaluators
|
||||
test_lrec_evaluators
|
||||
test-join-bucket-keeper
|
||||
|
|
@ -69,6 +70,7 @@ test_lrec
|
|||
test_mlrutil
|
||||
test_mlrregex
|
||||
test_multiple_containers
|
||||
test_mlhmmv
|
||||
test_parse_trie
|
||||
test_peek_file_reader
|
||||
test_string_builder
|
||||
|
|
|
|||
|
|
@ -140,7 +140,7 @@ TEST_MLHMMV_SRCS = \
|
|||
lib/mlrutil.c \
|
||||
lib/mlr_globals.c \
|
||||
containers/mlhmmv.c \
|
||||
containers/sllv.c \
|
||||
containers/sllmv.c \
|
||||
unit_test/test_mlhmmv.c
|
||||
|
||||
TEST_MLRUTIL_SRCS = \
|
||||
|
|
|
|||
|
|
@ -41,6 +41,8 @@ libcontainers_la_SOURCES= \
|
|||
slls.h \
|
||||
sllv.c \
|
||||
sllv.h \
|
||||
sllmv.c \
|
||||
sllmv.h \
|
||||
top_keeper.c \
|
||||
top_keeper.h
|
||||
libcontainers_la_LIBADD= \
|
||||
|
|
|
|||
|
|
@ -140,11 +140,13 @@ static void mlhmmv_level_free(mlhmmv_level_t* plevel) {
|
|||
//}
|
||||
|
||||
// ----------------------------------------------------------------
|
||||
void mlhmmv_put(mlhmmv_t* pmap, sllv_t* pmkeys, mv_t* pvalue) {
|
||||
void mlhmmv_put(mlhmmv_t* pmap, sllmv_t* pmkeys, mv_t* pvalue) {
|
||||
}
|
||||
|
||||
// level-put material:
|
||||
// if ((pmap->num_occupied + pmap->num_freed) >= (pmap->array_length*LOAD_FACTOR))
|
||||
// mlhmmv_enlarge(pmap);
|
||||
// return mlhmmv_put_no_enlarge(pmap, key, pvvalue, free_flags);
|
||||
}
|
||||
|
||||
//static void* mlhmmv_put_no_enlarge(mlhmmv_t* pmap, slls_t* key, void* pvvalue, char free_flags) {
|
||||
// int index = mlhmmv_find_index_for_key(pmap, key);
|
||||
|
|
@ -191,7 +193,7 @@ void mlhmmv_put(mlhmmv_t* pmap, sllv_t* pmkeys, mv_t* pvalue) {
|
|||
//}
|
||||
|
||||
// ----------------------------------------------------------------
|
||||
mv_t* mlhmmv_get(mlhmmv_t* pmap, sllv_t* pmvkeys) {
|
||||
mv_t* mlhmmv_get(mlhmmv_t* pmap, sllmv_t* pmvkeys) {
|
||||
// int index = mlhmmv_find_index_for_key(pmap, key);
|
||||
// mlhmmv_entry_t* pe = &pmap->entries[index];
|
||||
//
|
||||
|
|
@ -207,7 +209,7 @@ mv_t* mlhmmv_get(mlhmmv_t* pmap, sllv_t* pmvkeys) {
|
|||
}
|
||||
|
||||
// ----------------------------------------------------------------
|
||||
int mlhmmv_has_keys(mlhmmv_t* pmap, sllv_t* pmvkeys) {
|
||||
int mlhmmv_has_keys(mlhmmv_t* pmap, sllmv_t* pmvkeys) {
|
||||
// int index = mlhmmv_find_index_for_key(pmap, key);
|
||||
//
|
||||
// if (pmap->states[index] == OCCUPIED)
|
||||
|
|
@ -306,3 +308,11 @@ int mlhmmv_has_keys(mlhmmv_t* pmap, sllv_t* pmvkeys) {
|
|||
// pe->ideal_index, key_string, value_string);
|
||||
// }
|
||||
//}
|
||||
|
||||
// ----------------------------------------------------------------
|
||||
mlhmmv_value_t* mlhmmv_value_from_mv(mv_t* pmv) {
|
||||
mlhmmv_value_t* pvalue = mlr_malloc_or_die(sizeof(mlhmmv_value_t));
|
||||
pvalue->type = MLHMMV_VALUE_TYPE_TERMINAL;
|
||||
pvalue->u.mlrval = mv_copy(pmv);
|
||||
return pvalue;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -17,7 +17,7 @@
|
|||
#define MLHMMV_H
|
||||
|
||||
#include "containers/mlrval.h"
|
||||
#include "containers/sllv.h"
|
||||
#include "containers/sllmv.h"
|
||||
|
||||
#define MLHMMV_VALUE_TYPE_TERMINAL 0xabcd
|
||||
#define MLHMMV_VALUE_TYPE_NON_TERMINAL 0xfedc
|
||||
|
|
@ -61,9 +61,11 @@ typedef struct _mlhmmv_t {
|
|||
mlhmmv_t* mlhmmv_alloc();
|
||||
void mlhmmv_free(mlhmmv_t* pmap);
|
||||
// pmkeys is a list of mlhmmv_value_t
|
||||
void mlhmmv_put(mlhmmv_t* pmap, sllv_t* pmvkeys, mv_t* pvalue);
|
||||
mv_t* mlhmmv_get(mlhmmv_t* pmap, sllv_t* pmvkeys);
|
||||
int mlhmmv_has_keys(mlhmmv_t* pmap, sllv_t* pmvkeys);
|
||||
void mlhmmv_put(mlhmmv_t* pmap, sllmv_t* pmvkeys, mv_t* pvalue);
|
||||
mv_t* mlhmmv_get(mlhmmv_t* pmap, sllmv_t* pmvkeys);
|
||||
int mlhmmv_has_keys(mlhmmv_t* pmap, sllmv_t* pmvkeys);
|
||||
|
||||
mlhmmv_value_t* mlhmmv_value_from_mv(mv_t* pmv);
|
||||
|
||||
//// Unit-test hook
|
||||
//int mlhmmv_check_counts(mlhmmv_t* pmap);
|
||||
|
|
|
|||
|
|
@ -149,6 +149,12 @@ static inline mv_t mv_copy(mv_t* pval) {
|
|||
}
|
||||
}
|
||||
|
||||
static inline mv_t* mv_alloc_copy(mv_t* pold) {
|
||||
mv_t* pnew = mlr_malloc_or_die(sizeof(mv_t));
|
||||
*pnew = mv_copy(pold);
|
||||
return pnew;
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------
|
||||
static inline int mv_is_numeric(mv_t* pval) {
|
||||
return pval->type == MT_INT || pval->type == MT_FLOAT;
|
||||
|
|
|
|||
67
c/containers/sllmv.c
Normal file
67
c/containers/sllmv.c
Normal file
|
|
@ -0,0 +1,67 @@
|
|||
#include "lib/mlrutil.h"
|
||||
#include "containers/sllmv.h"
|
||||
|
||||
// ----------------------------------------------------------------
|
||||
sllmv_t* sllmv_alloc() {
|
||||
sllmv_t* plist = mlr_malloc_or_die(sizeof(sllmv_t));
|
||||
plist->phead = NULL;
|
||||
plist->ptail = NULL;
|
||||
plist->length = 0;
|
||||
return plist;
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------
|
||||
void sllmv_free(sllmv_t* plist) {
|
||||
if (plist == NULL)
|
||||
return;
|
||||
sllmve_t* pnode = plist->phead;
|
||||
while (pnode != NULL) {
|
||||
sllmve_t* pdel = pnode;
|
||||
pnode = pnode->pnext;
|
||||
mv_free(pdel->pvalue);
|
||||
free(pdel);
|
||||
}
|
||||
plist->phead = NULL;
|
||||
plist->ptail = 0;
|
||||
plist->length = 0;
|
||||
|
||||
free(plist);
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------
|
||||
void sllmv_add(sllmv_t* plist, mv_t* pvalue) {
|
||||
sllmve_t* pnode = mlr_malloc_or_die(sizeof(sllmve_t));
|
||||
pnode->pvalue = mv_alloc_copy(pvalue);
|
||||
if (plist->ptail == NULL) {
|
||||
pnode->pnext = NULL;
|
||||
plist->phead = pnode;
|
||||
plist->ptail = pnode;
|
||||
} else {
|
||||
pnode->pnext = NULL;
|
||||
plist->ptail->pnext = pnode;
|
||||
plist->ptail = pnode;
|
||||
}
|
||||
plist->length++;
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------
|
||||
sllmv_t* sllmv_single(mv_t* pvalue) {
|
||||
sllmv_t* psllmv = sllmv_alloc();
|
||||
sllmv_add(psllmv, pvalue);
|
||||
return psllmv;
|
||||
}
|
||||
|
||||
sllmv_t* sllmv_double(mv_t* pvalue1, mv_t* pvalue2) {
|
||||
sllmv_t* psllmv = sllmv_alloc();
|
||||
sllmv_add(psllmv, pvalue1);
|
||||
sllmv_add(psllmv, pvalue2);
|
||||
return psllmv;
|
||||
}
|
||||
|
||||
sllmv_t* sllmv_triple(mv_t* pvalue1, mv_t* pvalue2, mv_t* pvalue3) {
|
||||
sllmv_t* psllmv = sllmv_alloc();
|
||||
sllmv_add(psllmv, pvalue1);
|
||||
sllmv_add(psllmv, pvalue2);
|
||||
sllmv_add(psllmv, pvalue3);
|
||||
return psllmv;
|
||||
}
|
||||
31
c/containers/sllmv.h
Normal file
31
c/containers/sllmv.h
Normal file
|
|
@ -0,0 +1,31 @@
|
|||
// ================================================================
|
||||
// Singly-linked list of mlrval, with tail for append.
|
||||
// Everything is copied; nothing is referenced.
|
||||
// ================================================================
|
||||
|
||||
#ifndef SLLMV_H
|
||||
#define SLLMV_H
|
||||
|
||||
#include "mlrval.h"
|
||||
|
||||
typedef struct _sllmve_t {
|
||||
mv_t* pvalue;
|
||||
struct _sllmve_t *pnext;
|
||||
} sllmve_t;
|
||||
|
||||
typedef struct _sllmv_t {
|
||||
sllmve_t *phead;
|
||||
sllmve_t *ptail;
|
||||
int length;
|
||||
} sllmv_t;
|
||||
|
||||
sllmv_t* sllmv_alloc();
|
||||
void sllmv_free(sllmv_t* plist);
|
||||
void sllmv_add(sllmv_t* plist, mv_t* pvalue);
|
||||
|
||||
sllmv_t* sllmv_single(mv_t* pvalue);
|
||||
sllmv_t* sllmv_double(mv_t* pvalue1, mv_t* pvalue2);
|
||||
sllmv_t* sllmv_triple(mv_t* pvalue1, mv_t* pvalue2, mv_t* pvalue3);
|
||||
|
||||
#endif // SLLMV_H
|
||||
|
||||
|
|
@ -13,6 +13,18 @@ int assertions_failed = 0;
|
|||
static char* test_stub() {
|
||||
mu_assert_lf(0 == 0);
|
||||
|
||||
mlhmmv_t* pmap = mlhmmv_alloc();
|
||||
|
||||
mv_t key = mv_from_int(3LL);
|
||||
sllmv_t* pmkeys = sllmv_single(&key);
|
||||
mv_t value = mv_from_int(4LL);
|
||||
|
||||
mlhmmv_put(pmap, pmkeys, &value);
|
||||
|
||||
sllmv_free(pmkeys);
|
||||
|
||||
mlhmmv_free(pmap);
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue