summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYorhel <git@yorhel.nl>2010-04-29 10:50:41 +0200
committerYorhel <git@yorhel.nl>2010-04-29 10:50:41 +0200
commiteea8d21d3ff446753c63c88b377767b3ac631365 (patch)
treedf753a88e96f873f5938c744e4cbcaa5c8f5f1ed
parent7aaacf7f48c01ca5ce7c3ab369403279b8b86866 (diff)
Implemented compll_read() and compll_write()
The library is now done, functionality-wise. What follows are testing and performance optimization.
-rw-r--r--compll.c42
1 files changed, 38 insertions, 4 deletions
diff --git a/compll.c b/compll.c
index 3745960..064c505 100644
--- a/compll.c
+++ b/compll.c
@@ -220,6 +220,10 @@ static int block_alloc() {
static int block_load(int ab) {
int ub;
+ /* sanity checking, ab can come directly from the application */
+ if(ab >= ablocks_size || ab < 0 || (!ablocks[ab].data && ablocks[ab].ublock < 0))
+ return -1;
+
/* don't do anything if the block is already loaded */
if(ablocks[ab].ublock >= 0) {
ublock_access(ablocks[ab].ublock);
@@ -522,6 +526,35 @@ void compll_free(compll_t node) {
+const void *compll_read(compll_t node) {
+ int ab = node >> 24,
+ off = node & 0xFFFFFF,
+ ub;
+ if((ub = block_load(ab)) < 0)
+ return NULL;
+ return ublocks[ub].data + off;
+}
+
+
+
+void *compll_write(compll_t node) {
+ int ab = node >> 24,
+ off = node & 0xFFFFFF,
+ ub;
+ if((ub = block_load(ab)) < 0)
+ return NULL;
+
+ /* invalidate the compressed data */
+ if(ablocks[ab].data) {
+ free(ablocks[ab].data);
+ ablocks[ab].data = NULL;
+ }
+
+ return ublocks[ub].data + off;
+}
+
+
+
int compll_init(unsigned int block_size,
unsigned short alignment,
unsigned short uncomp_count,
@@ -617,15 +650,16 @@ void dbg_decompress(const unsigned char *src, unsigned int srclen, unsigned char
int main() {
- int i, off;
+ int i;
compll_t m;
FILE *f;
- printf("compll_init = %d\n", compll_init(1<<16, 8, 10, dbg_compress, dbg_decompress));
+ printf("compll_init = %d\n", compll_init(1024, 1, 10, dbg_compress, dbg_decompress));
for(i=4; i<=16; i+=4) {
- off = compll_alloc(i);
- printf("compll_alloc(%d) = %d (free = %d)\n", i, off, ablocks[0].free);
+ m = compll_alloc(i);
+ printf("compll_alloc(%d) = %llu (free = %d)\n", i, m, ablocks[0].free);
+ memset(compll_write(m), i, i);
}
m = compll_alloc(500);