From eea8d21d3ff446753c63c88b377767b3ac631365 Mon Sep 17 00:00:00 2001 From: Yorhel Date: Thu, 29 Apr 2010 10:50:41 +0200 Subject: Implemented compll_read() and compll_write() The library is now done, functionality-wise. What follows are testing and performance optimization. --- compll.c | 42 ++++++++++++++++++++++++++++++++++++++---- 1 file 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); -- cgit v1.2.3