commit 025941c71cc428011b16e15d2cbd9a78eb09f753
parent 34e545c3b4ad4f558404f812db2f1056de8d288a
Author: Plat <plat@stellar-nexus.ru>
Date: Fri, 7 Nov 2025 08:54:43 +0000
Various fixes to fib.c
Diffstat:
3 files changed, 18 insertions(+), 18 deletions(-)
diff --git a/Makefile b/Makefile
@@ -1,18 +1,18 @@
include config.mk
BIN = fib rb
LIBS = ${wildcard libutil/*.c}
-OBJS = rb.o ${LIBS:.c=.o}
+OBJS = ${BIN:%=%.o} ${LIBS:.c=.o}
all: ${BIN}
-${BIN}: ${OBJS}
- ${CC} ${CFLAGS} -o $@ ${OBJS} ${LDFLAGS}
+${BIN}: ${BIN:%=%.o} ${OBJS}
+ ${CC} ${CFLAGS} -o $@ $@.o ${OBJS} ${LDFLAGS}
strip $@
%.o: %.c
${CC} ${CFLAGS} -c $< -o $@
clean:
- rm -f rb ${OBJS}
+ rm -f ${BIN} ${BIN:%=%.o} ${OBJS}
.PHONY: all clean
diff --git a/fib.c b/fib.c
@@ -9,7 +9,7 @@ typedef struct Fnode Node;
inline Node *
-init(void)
+finit(void)
{
Node *root = emalloc(sizeof(Node));
@@ -27,11 +27,11 @@ create(unsigned int depth)
return NULL;
case 1:
case 2:
- return init();
+ return finit();
default:
- Node *root = init();
+ Node *root = finit();
root->left = create(depth - 1);
- root->right = init()
+ root->right = finit();
root->right->right = create(depth-2);
return root;
}
@@ -76,7 +76,7 @@ main(int argc, char *argv[])
clock_t start_time, time = 0;
if (cflag)
start_time = clock();
- Node *root = create(strtonum(argv[1], 0, UINT_MAX));
+ Node *root = create(estrtonum(argv[1], 0, UINT_MAX));
time += clock() - start_time;
volatile unsigned long int fib = 0; /* to avoid optimization */
diff --git a/tree.h b/tree.h
@@ -18,16 +18,16 @@ struct Fnode {
};
static inline struct Node *init(int);
-Node *add(struct Node *, int);
-Node *parse_pre(struct Node *);
-Node *parse_post(struct Node *);
-Node *parse_inf(struct Node *);
+struct Node *add(struct Node *, int);
+struct Node *parse_pre(struct Node *);
+struct Node *parse_post(struct Node *);
+struct Node *parse_inf(struct Node *);
int get_height(struct Node *);
-Node *balance(struct Node *);
-Node *left_turn(struct Node *);
-Node *right_turn(struct Node *);
-Node *search(struct Node *, int);
+struct Node *balance(struct Node *);
+struct Node *left_turn(struct Node *);
+struct Node *right_turn(struct Node *);
+struct Node *search(struct Node *, int);
static inline struct Fnode *finit(void);
struct Fnode *create(unsigned int);
-unsigned long int search(struct Fnode *);
+unsigned long int count(struct Fnode *);