summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBernd Schubert <bernd.schubert@fastmail.fm>2010-07-04 17:47:38 +0200
committerBernd Schubert <bernd.schubert@fastmail.fm>2010-07-04 17:47:38 +0200
commitf3902a606d13ad17cace533c564172e77ba108db (patch)
treec558fb6657a7c1ef72c437655036086673d0e46b
parentb44bc9b60a8e073874092d49f369f058f35b16d1 (diff)
downloadunionfs-fuse-f3902a606d13ad17cace533c564172e77ba108db.tar.gz
Remove dependency on libm
Introduce our own ceil implementation into the hash table functions, so that we don't need to link against libm anymore.
-rw-r--r--src/CMakeLists.txt2
-rw-r--r--src/Makefile1
-rw-r--r--src/hashtable.c24
3 files changed, 22 insertions, 5 deletions
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index 708ac18..970d882 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -2,6 +2,6 @@ set(HASHTABLE_SRCS hashtable.c hashtable_itr.c)
set(UNIONFS_SRCS unionfs.c stats.c opts.c debug.c findbranch.c readdir.c general.c unlink.c cow.c cow_utils.c string.c rmdir.c)
add_executable(unionfs ${UNIONFS_SRCS} ${HASHTABLE_SRCS})
-target_link_libraries(unionfs fuse pthread m rt)
+target_link_libraries(unionfs fuse pthread rt)
INSTALL(PROGRAMS ${CMAKE_CURRENT_BINARY_DIR}/unionfs DESTINATION bin)
diff --git a/src/Makefile b/src/Makefile
index df98c94..2f51bf5 100644
--- a/src/Makefile
+++ b/src/Makefile
@@ -6,7 +6,6 @@ CPPFLAGS += -DFUSE_USE_VERSION=26
LDFLAGS +=
LIB = $(shell pkg-config --libs fuse)
-LIB += -lm # For ceil(3)
HASHTABLE_OBJ = hashtable.o hashtable_itr.o
UNIONFS_OBJ = unionfs.o stats.o opts.o debug.o findbranch.o readdir.o general.o unlink.o rmdir.o cow.o cow_utils.o string.o
diff --git a/src/hashtable.c b/src/hashtable.c
index 763357e..ac29af3 100644
--- a/src/hashtable.c
+++ b/src/hashtable.c
@@ -5,7 +5,6 @@
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
-#include <math.h>
/*
Credit for primes table: Aaron Krowne
@@ -24,6 +23,25 @@ static const unsigned int primes[] = {
const unsigned int prime_table_length = sizeof(primes)/sizeof(primes[0]);
const float max_load_factor = 0.65;
+#define TOL 1e-6 // float tolerance
+
+/**
+ * my_ceil - calculate ceil value
+ * Using C ceil() from math.h with -lm requires to link this library only for
+ * this simple function. As it is not performance relevent for the hash table
+ * we use our own * implementation.
+ *
+ */
+static int my_ceil(float x)
+{
+ int y = (int) x;
+ if (y - x > TOL)
+ return y;
+ else
+ return y + 1;
+}
+
+
/*****************************************************************************/
struct hashtable *
create_hashtable(unsigned int minsize,
@@ -48,7 +66,7 @@ create_hashtable(unsigned int minsize,
h->entrycount = 0;
h->hashfn = hashf;
h->eqfn = eqf;
- h->loadlimit = (unsigned int) ceil(size * max_load_factor);
+ h->loadlimit = my_ceil(size * max_load_factor);
return h;
}
@@ -121,7 +139,7 @@ hashtable_expand(struct hashtable *h)
}
}
h->tablelength = newsize;
- h->loadlimit = (unsigned int) ceil(newsize * max_load_factor);
+ h->loadlimit = my_ceil(newsize * max_load_factor);
return -1;
}