Skip to content

Commit

Permalink
node cdp needs renaming
Browse files Browse the repository at this point in the history
git-svn-id: file:///Users/avp/tmp/svn.20121212/LHPC/aff/trunk@103 65d2813f-f11f-0410-b17b-8647a28db151
  • Loading branch information
avp committed Aug 18, 2007
1 parent 4cc8745 commit d4d7577
Show file tree
Hide file tree
Showing 28 changed files with 309 additions and 98 deletions.
16 changes: 14 additions & 2 deletions lib/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ sources=$(treap.sources) \
$(tree.sources) \
$(node.sources)

treap.sources = treap-extend.c \
treap.sources = treap-insert.c \
treap-fini.c \
treap-init.c \
treap-lookup.c \
Expand Down Expand Up @@ -49,7 +49,18 @@ tree.sources = tree-fini.c \
tree.headers = tree-i.h \
tree.h

node.sources = node-foreach.c
node.sources = node-foreach.c \
node-id.c \
node-name.c \
node-parent.c \
node-type.c \
node-size.c \
node-offset.c \
node-assign.c \
node-cda.c \
node-cdp.c \
node-cdv.c \
node-cd.c

node.headers = node-i.h \
node.h
Expand All @@ -75,6 +86,7 @@ $(library): $(sources:%.c=%.o)
$(sources:%.c=%.o): %.o: %.c
$(CC) $(CFLAGS) -c -o $@ $<

$(node.sources:%.c=%.o): $(node.headers)
$(treap.sources:%.c=%.o): $(treap.headers)
$(stable.sources:%.c=%.o): $(stable.headers) treap.h
$(tree.sources:%.c=%.o): $(tree.headers) treap.h stable.h node.h node-i.h
15 changes: 6 additions & 9 deletions lib/node-assign.c
Original file line number Diff line number Diff line change
@@ -1,15 +1,12 @@
#include <stdint.h>
#include <stdlib.h>
#include <string.h>
#include "treap.h"
#include "stable.h"
#include "tree-i.h"
#include <stdarg.h>
#include "node-i.h"

int
aff_n_assign(struct AffTreeNode_s *node,
enum AffNodeType_e type,
uint32_t size,
uint64_t offset)
aff_node_assign(struct AffNode_s *node,
enum AffNodeType_e type,
uint32_t size,
uint64_t offset)
{
if (node == 0)
return 1;
Expand Down
20 changes: 20 additions & 0 deletions lib/node-cd.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#include <stdint.h>
#include <stdarg.h>
#include "node-i.h"

struct AffNode_s *
aff_node_cd(struct AffTree_s *tree,
struct AffSTable_s *stable,
struct AffNode_s *n,
int create,
...)
{
struct AffNode_s *res;
va_list va;

va_start(va, create);
res = aff_node_cdv(tree, stable, n, create, va);
va_end(va);

return res;
}
14 changes: 14 additions & 0 deletions lib/node-cda.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#include <stdint.h>
#include <stdarg.h>
#include "node-i.h"

struct AffNode_s *
aff_node_cda(struct AffTree_s *tree,
struct AffSTable_s *stable,
struct AffNode_s *n,
int create,
const char *p[])
{
/* XXX */
return 0;
}
35 changes: 35 additions & 0 deletions lib/node-cdp.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#include <stdint.h>
#include <stdarg.h>
#include "stable.h"
#include "node.h"
#include "tree.h"
#include "node-i.h"

struct AffNode_s *
aff_node_chdir(struct AffTree_s *tree,
struct AffSTable_s *stable,
struct AffNode_s *n,
int create,
const char *p)
{
const struct AffSymbol_s *sym;
struct AffNode_s *ch;

if (tree == 0 || stable == 0 || n == 0)
return 0;
if (p == 0)
return n;

sym = aff_stable_lookup(stable, p);
if (sym == 0 && create) {
sym = aff_stable_insert(stable, p);
}
if (sym == 0)
return 0;

ch = aff_tree_lookup(tree, n, sym);
if (ch == 0 && create) {
ch = aff_tree_insert(tree, n, sym);
}
return ch;
}
20 changes: 20 additions & 0 deletions lib/node-cdv.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#include <stdint.h>
#include <stdarg.h>
#include "node-i.h"

struct AffNode_s *
aff_node_cdv(struct AffTree_s *tree,
struct AffSTable_s *stable,
struct AffNode_s *n,
int create,
va_list va)
{
const char *name;

for (;;) {
name = va_arg(va, const char *);
if (name == 0)
return n;
n = aff_node_chdir(tree, stable, n, create, name);
}
}
7 changes: 3 additions & 4 deletions lib/node-id.c
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
#include <stdint.h>
#include "treap.h"
#include "stable.h"
#include "tree-i.h"
#include <stdarg.h>
#include "node-i.h"

uint64_t
aff_n_id(const struct AffTreeNode_s *tn)
aff_node_id(const struct AffNode_s *tn)
{
if (tn == 0)
return 0;
Expand Down
7 changes: 3 additions & 4 deletions lib/node-name.c
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
#include <stdint.h>
#include "treap.h"
#include "stable.h"
#include "tree-i.h"
#include <stdarg.h>
#include "node-i.h"

const struct AffSymbol_s *
aff_n_name(const struct AffTreeNode_s *tn)
aff_node_name(const struct AffNode_s *tn)
{
if (tn == 0)
return 0;
Expand Down
7 changes: 3 additions & 4 deletions lib/node-offset.c
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
#include <stdint.h>
#include "treap.h"
#include "stable.h"
#include "tree-i.h"
#include <stdarg.h>
#include "node-i.h"

uint64_t
aff_n_offset(const struct AffTreeNode_s *tn)
aff_node_offset(const struct AffNode_s *tn)
{
if (tn == 0)
return 0;
Expand Down
11 changes: 5 additions & 6 deletions lib/node-parent.c
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
#include <stdint.h>
#include "treap.h"
#include "stable.h"
#include "tree-i.h"
#include <stdarg.h>
#include "node-i.h"

const struct AffTreeNode_s *
aff_n_parent(const struct AffTreeNode_s *tn)
struct AffNode_s *
aff_node_parent(const struct AffNode_s *tn)
{
if (tn == 0)
return 0;
return tn->key.parent;
return (struct AffNode_s *)tn->key.parent;
}
11 changes: 11 additions & 0 deletions lib/node-size.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#include <stdint.h>
#include <stdarg.h>
#include "node-i.h"

uint32_t
aff_node_size(const struct AffNode_s *tn)
{
if (tn == 0)
return 0;
return tn->size;
}
7 changes: 3 additions & 4 deletions lib/node-type.c
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
#include <stdint.h>
#include "treap.h"
#include "stable.h"
#include "tree-i.h"
#include <stdarg.h>
#include "node-i.h"


enum AffNodeType_e
aff_n_type(const struct AffTreeNode_s *tn)
aff_node_type(const struct AffNode_s *tn)
{
if (tn == 0)
return affNodeInvalid;
Expand Down
31 changes: 12 additions & 19 deletions lib/node.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@
* otherwise, missing components will be added to the tree and symbol table.
*
* cda() walks through a given sequence of path elments. The list ends with NULL
* cdp() takes a linked list of path elements in the reverse order and walks it
* cd() takes a list as separate arguments, the last argument must be NULL.
* cdv() takes arguments of cd() converted into va_list.
* chdir() moves one step through the tree.
*
* There are also node manipulation routines in AFF readers and writers.
*/
Expand All @@ -39,12 +39,6 @@ enum AffNodeType_e {
affNodeComplex
};

/* AFF reverse path structure */
struct AffReversePath_s {
const struct AffReversePath_s *parent;
const char *name;
};

struct AffTree_s;
struct AffSTable_s;

Expand All @@ -53,8 +47,8 @@ void aff_node_foreach(struct AffNode_s *n,
void *arg),
void *arg);
uint64_t aff_node_id(const struct AffNode_s *tn);
const struct AFfSymbol_s*aff_node_name(const struct AffNode_s *n);
struct AffNode_t *aff_node_parent(const struct AffNode_s *n);
const struct AffSymbol_s*aff_node_name(const struct AffNode_s *n);
struct AffNode_s *aff_node_parent(const struct AffNode_s *n);
enum AffNodeType_e aff_node_type(const struct AffNode_s *n);
uint32_t aff_node_size(const struct AffNode_s *n);
uint64_t aff_node_offset(const struct AffNode_s *tn);
Expand All @@ -63,26 +57,25 @@ int aff_node_assign(struct AffNode_s *node,
uint32_t size,
uint64_t offset);

struct AffNode_t *aff_node_cda(struct AffTree_s *tree,
struct AffNode_s *aff_node_chdir(struct AffTree_s *tree,
struct AffSTable_s *stable,
struct AffNode_s *n,
int create,
const char *p);
struct AffNode_s *aff_node_cda(struct AffTree_s *tree,
struct AffSTable_s *stable,
struct AffNode_s *n,
int create,
const char *p[]);
struct AffNode_t *aff_node_cdp(struct AffTree_s *tree,
struct AffSTable_s *stable,
struct AffNode_s *n,
int create,
struct AffReversePath_s *rp);
struct AffNode_t *aff_node_cdv(struct AffTree_s *tree,
struct AffNode_s *aff_node_cdv(struct AffTree_s *tree,
struct AffSTable_s *stable,
struct AffNode_s *n,
int create,
va_list va);
struct AffNode_t *aff_node_cd(struct AffTree_s *tree,
struct AffNode_s *aff_node_cd(struct AffTree_s *tree,
struct AffSTable_s *stable,
struct AffNode_s *n,
int create,
const char *name, ...);

...);

#endif /* !defined(MARK_a4d076cf_516e_4864_861a_ed8239937ca5) */
4 changes: 2 additions & 2 deletions lib/stable-insert.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ aff_stable_insert(struct AffSTable_s *st, const char *name)
b = malloc(sizeof (struct Block_s));
if (b == 0)
return 0;
aff_st_iblock(b, st->size + 1);
aff_stable_iblock(b, st->size + 1);
st->last_block->next = b;
st->last_block = b;
}
Expand All @@ -33,7 +33,7 @@ aff_stable_insert(struct AffSTable_s *st, const char *name)
if (sym->name == 0)
return 0;
sym->id = st->size + 1;
if (aff_treap_extend(st->treap, sym->name, len, sym) != 0) {
if (aff_treap_insert(st->treap, sym->name, len, sym) != 0) {
free((void *)sym->name);
return 0;
}
Expand Down
2 changes: 1 addition & 1 deletion lib/treap-extend.c → lib/treap-insert.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#include "treap-i.h"

int
aff_treap_extend(struct AffTreap_s *h, const void *key, int size, void *data)
aff_treap_insert(struct AffTreap_s *h, const void *key, int size, void *data)
{
struct Node_s *q;
struct Node_s *p;
Expand Down
6 changes: 4 additions & 2 deletions lib/tree-fini.c
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@
#include <stdint.h>
#include <stdlib.h>
#include <stdarg.h>
#include "treap.h"
#include "stable.h"
#include "node-i.h"
#include "tree-i.h"

void *
aff_tt_fini(struct AffTree_s *tt)
aff_tree_fini(struct AffTree_s *tt)
{
struct Block_s *bl;

if (tt == 0)
return 0;
aff_h_fini(tt->treap);
aff_treap_fini(tt->treap);
for (bl = tt->block.next; bl;) {
struct Block_s *n = bl->next;
free(bl);
Expand Down
10 changes: 6 additions & 4 deletions lib/tree-foreach.c
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
#include <stdint.h>
#include <stdarg.h>
#include "treap.h"
#include "stable.h"
#include "node-i.h"
#include "tree-i.h"

void
aff_tt_foreach(const struct AffTree_s *tt,
void (*proc)(const struct AffTreeNode_s *node, void *arg),
void *arg)
aff_tree_foreach(const struct AffTree_s *tt,
void (*proc)(struct AffNode_s *node, void *arg),
void *arg)
{
const struct Block_s *b;
uint32_t i;
Expand All @@ -16,7 +18,7 @@ aff_tt_foreach(const struct AffTree_s *tt,

for (b = &tt->block; b; b = b->next) {
for (i = 0; i < b->used; i++) {
proc(b->node, arg);
proc((struct AffNode_s *)b->node, arg);
}
}
}
4 changes: 3 additions & 1 deletion lib/tree-fsize.c
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
#include <stdint.h>
#include <stdarg.h>
#include "treap.h"
#include "stable.h"
#include "node-i.h"
#include "tree-i.h"

uint64_t
aff_tt_file_size(const struct AffTree_s *tt)
aff_tree_file_size(const struct AffTree_s *tt)
{
if (tt == 0)
return 0;
Expand Down
Loading

0 comments on commit d4d7577

Please sign in to comment.