From: <ny...@us...> - 2006-12-27 19:22:37
|
Revision: 211 http://svn.sourceforge.net/pmplib/?rev=211&view=rev Author: nyaochi Date: 2006-12-27 11:22:33 -0800 (Wed, 27 Dec 2006) Log Message: ----------- Source code clean-up for idx.c Modified Paths: -------------- trunk/pmplib/lib/pmp_iriverplus3/idx.c Modified: trunk/pmplib/lib/pmp_iriverplus3/idx.c =================================================================== --- trunk/pmplib/lib/pmp_iriverplus3/idx.c 2006-12-27 19:11:11 UTC (rev 210) +++ trunk/pmplib/lib/pmp_iriverplus3/idx.c 2006-12-27 19:22:33 UTC (rev 211) @@ -26,6 +26,9 @@ - This file seems to have 12-bytes header - Indices consist of multiple binary search trees - The offset addresses to the root nodes are specified in db.dic + +Implementation note: +- The AVL trees are */ #ifdef HAVE_CONFIG_H @@ -47,12 +50,6 @@ #define COMP(a, b) ((a)>(b))-((a)<(b)) -typedef struct { - uint32_t size; - uint32_t unknown1; - uint32_t unknown2; -} idx_header_t; - struct tag_avlnode_t { uint32_t left; uint32_t right; @@ -312,7 +309,6 @@ break; } - memcpy(avlnode(avl, offset_key), key, size); ret = avl_insert(avl, root, &offset_this, comp[type]); if (ret != -1) { /* A new key. */ @@ -326,19 +322,8 @@ } } -static int avl_insert_keydata(avl_t* avl, const void* key, int type, uint32_t data, uint32_t* root) -{ - uint32_t offset = 0; - int ret = avl_insert_key(avl, key, type, &offset, root); - avlnode_t* node = avlnode(avl, offset); - uint32_t offset_tail = avltail_new(avl); - avltail_t* tail = (avltail_t*)avlnode(avl, offset_tail); - tail->data = data; - tail->next = node->tail; - node->tail = offset_tail; - return ret; -} + static void from_uint16be(uint16_t* value) { uint8_t* src = (uint8_t*)value; @@ -514,6 +499,9 @@ return height; } + + + static void fprinti(FILE *fp, int n) { while (n--) fputc(' ', fp); @@ -590,36 +578,13 @@ } } -void avl_walk2(avl_t* avl, uint32_t offr, avl_comp_t comp) -{ - wchar_t* key = 0; - avlnode_t* root = avlnode(avl, offr); - avltail_t* tail = (avltail_t*)avlnode(avl, root->tail); - if (root->left) avl_walk2(avl, root->left, comp); - key = (wchar_t*)avlnode(avl, offr + sizeof(avlnode_t)); - printf("%S: ", key); - for (;;) { - printf("%d ", tail->data); - if (!tail->next) { - break; - } - tail = (avltail_t*)avlnode(avl, tail->next); - } - printf("\n"); - if (root->right) avl_walk2(avl, root->right, comp); -} -void avl_walk(avl_t* avl, uint32_t offr, avl_comp_t comp) -{ - wchar_t* key = 0; - avlnode_t* root = avlnode(avl, offr); - if (root->left) avl_walk(avl, root->left, comp); - key = (wchar_t*)avlnode(avl, offr + sizeof(avlnode_t)); - printf("%S: ", key); - avl_walk2(avl, root->tail, comp); - if (root->right) avl_walk(avl, root->right, comp); -} +typedef struct { + uint32_t size; + uint32_t unknown1; + uint32_t unknown2; +} idx_header_t; idx_t *idx_new() { @@ -656,7 +621,7 @@ from_uint32be(&header->unknown1); from_uint32be(&header->unknown2); - /* Convert the byte order of AVL trees. */ + /* Convert the byte order of values in AVL trees. */ for (i = 0;i < dic->music.num_indices;++i) { uint32_t idx_root = dic_get_idxroot(dic, IP3DBIDX_MUSIC, i); from_be_avltree(idx->avl, idx_root, &dic->music, i, 0); @@ -673,14 +638,15 @@ int i; idx_header_t* header = (idx_header_t*)idx->buffer; + /* The size fo db.idx equals to the maximum offset of the AVL trees. */ header->size = idx->avl->offset; - /* Convert the byte order of the header from big endian to the native one. */ + /* Convert the byte order of the header to big endian from the native one. */ to_uint32be(&header->size); to_uint32be(&header->unknown1); to_uint32be(&header->unknown2); - /* Convert the byte order of AVL trees. */ + /* Convert the byte order of values in AVL trees. */ for (i = 0;i < dic->music.num_indices;++i) { uint32_t idx_root = dic_get_idxroot(dic, IP3DBIDX_MUSIC, i); to_be_avltree(idx->avl, idx_root, &dic->music, i, 0); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |