Mercurial > hg > xmms-sid
comparison src/xs_length.c @ 96:3898d4fdbd49
Renamed some variables
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Sat, 10 Jan 2004 22:54:01 +0000 |
parents | 2607683bc9eb |
children | 2bc56809ec0b |
comparison
equal
deleted
inserted
replaced
95:4e929bb71057 | 96:3898d4fdbd49 |
---|---|
29 | 29 |
30 | 30 |
31 /* | 31 /* |
32 * Pointer to database in memory | 32 * Pointer to database in memory |
33 */ | 33 */ |
34 static t_xs_sldb_node *xs_database = NULL; | 34 static t_xs_sldb_node *xs_sldb = NULL; |
35 static t_xs_sldb_node **xs_dbindex = NULL; | 35 static t_xs_sldb_node **xs_sldbi = NULL; |
36 static gint xs_dbnodes = 0; | 36 static gint xs_sldbn = 0; |
37 | 37 |
38 | 38 |
39 /* | 39 /* |
40 * Hash-database handling functions | 40 * Hash-database handling functions |
41 */ | 41 */ |
64 #define LTHIS (pNode) | 64 #define LTHIS (pNode) |
65 #define LNEXT (pNode->pNext) | 65 #define LNEXT (pNode->pNext) |
66 | 66 |
67 void xs_db_node_insert(t_xs_sldb_node *pNode) | 67 void xs_db_node_insert(t_xs_sldb_node *pNode) |
68 { | 68 { |
69 if (xs_database) | 69 if (xs_sldb) |
70 { | 70 { |
71 /* The first node's pPrev points to last node */ | 71 /* The first node's pPrev points to last node */ |
72 LPREV = xs_database->pPrev; /* New node's prev = Previous last node */ | 72 LPREV = xs_sldb->pPrev; /* New node's prev = Previous last node */ |
73 xs_database->pPrev->pNext = pNode; /* Previous last node's next = New node */ | 73 xs_sldb->pPrev->pNext = pNode; /* Previous last node's next = New node */ |
74 xs_database->pPrev = pNode; /* New last node = New node */ | 74 xs_sldb->pPrev = pNode; /* New last node = New node */ |
75 LNEXT = NULL; /* But next is NULL! */ | 75 LNEXT = NULL; /* But next is NULL! */ |
76 } else { | 76 } else { |
77 xs_database = pNode; /* First node ... */ | 77 xs_sldb = pNode; /* First node ... */ |
78 LPREV = pNode; /* ... it's also last */ | 78 LPREV = pNode; /* ... it's also last */ |
79 LNEXT = NULL; /* But next is NULL! */ | 79 LNEXT = NULL; /* But next is NULL! */ |
80 } | 80 } |
81 } | 81 } |
82 | 82 |
107 gint iStartNode, iEndNode, iQNode, r, i; | 107 gint iStartNode, iEndNode, iQNode, r, i; |
108 gboolean iFound; | 108 gboolean iFound; |
109 t_xs_sldb_node *pResult; | 109 t_xs_sldb_node *pResult; |
110 | 110 |
111 /* Check the database pointers */ | 111 /* Check the database pointers */ |
112 if (!xs_database || !xs_dbindex) | 112 if (!xs_sldb || !xs_sldbi) |
113 return NULL; | 113 return NULL; |
114 | 114 |
115 /* Look-up via index using binary search */ | 115 /* Look-up via index using binary search */ |
116 pResult = NULL; | 116 pResult = NULL; |
117 iStartNode = 0; | 117 iStartNode = 0; |
118 iEndNode = (xs_dbnodes - 1); | 118 iEndNode = (xs_sldbn - 1); |
119 iQNode = (iEndNode / 2); | 119 iQNode = (iEndNode / 2); |
120 iFound = FALSE; | 120 iFound = FALSE; |
121 | 121 |
122 while ((!iFound) && ((iEndNode - iStartNode) > 128)) | 122 while ((!iFound) && ((iEndNode - iStartNode) > 128)) |
123 { | 123 { |
124 r = xs_db_cmphash(pHash, xs_dbindex[iQNode]->md5Hash); | 124 r = xs_db_cmphash(pHash, xs_sldbi[iQNode]->md5Hash); |
125 if (r < 0) | 125 if (r < 0) |
126 { | 126 { |
127 /* Hash was in the <- LEFT side */ | 127 /* Hash was in the <- LEFT side */ |
128 iEndNode = iQNode; | 128 iEndNode = iQNode; |
129 iQNode = iStartNode + ((iEndNode - iStartNode) / 2); | 129 iQNode = iStartNode + ((iEndNode - iStartNode) / 2); |
143 /* Search the are linearly */ | 143 /* Search the are linearly */ |
144 iFound = FALSE; | 144 iFound = FALSE; |
145 i = iStartNode; | 145 i = iStartNode; |
146 while ((i <= iEndNode) && (!iFound)) | 146 while ((i <= iEndNode) && (!iFound)) |
147 { | 147 { |
148 if (xs_db_cmphash(pHash, xs_dbindex[i]->md5Hash) == 0) | 148 if (xs_db_cmphash(pHash, xs_sldbi[i]->md5Hash) == 0) |
149 iFound = TRUE; | 149 iFound = TRUE; |
150 else | 150 else |
151 i++; | 151 i++; |
152 } | 152 } |
153 | 153 |
154 /* Check the result */ | 154 /* Check the result */ |
155 if (iFound) | 155 if (iFound) |
156 pResult = xs_dbindex[i]; | 156 pResult = xs_sldbi[i]; |
157 | 157 |
158 } else { | 158 } else { |
159 /* Found via binary search */ | 159 /* Found via binary search */ |
160 pResult = xs_dbindex[iQNode]; | 160 pResult = xs_sldbi[iQNode]; |
161 } | 161 } |
162 | 162 |
163 | 163 |
164 return pResult; | 164 return pResult; |
165 } | 165 } |
343 return -9; | 343 return -9; |
344 | 344 |
345 XSDEBUG("indexing...\n"); | 345 XSDEBUG("indexing...\n"); |
346 | 346 |
347 /* Get size of db */ | 347 /* Get size of db */ |
348 pCurr = xs_database; | 348 pCurr = xs_sldb; |
349 xs_dbnodes = 0; | 349 xs_sldbn = 0; |
350 while (pCurr) | 350 while (pCurr) |
351 { | 351 { |
352 xs_dbnodes++; | 352 xs_sldbn++; |
353 pCurr = pCurr->pNext; | 353 pCurr = pCurr->pNext; |
354 } | 354 } |
355 | 355 |
356 /* Check number of nodes */ | 356 /* Check number of nodes */ |
357 if (xs_dbnodes > 0) | 357 if (xs_sldbn > 0) |
358 { | 358 { |
359 /* Allocate memory for index-table */ | 359 /* Allocate memory for index-table */ |
360 xs_dbindex = (t_xs_sldb_node **) g_malloc(sizeof(t_xs_sldb_node *) * xs_dbnodes); | 360 xs_sldbi = (t_xs_sldb_node **) g_malloc(sizeof(t_xs_sldb_node *) * xs_sldbn); |
361 if (!xs_dbindex) return -6; | 361 if (!xs_sldbi) return -6; |
362 | 362 |
363 /* Get node-pointers to table */ | 363 /* Get node-pointers to table */ |
364 i = 0; | 364 i = 0; |
365 pCurr = xs_database; | 365 pCurr = xs_sldb; |
366 while (pCurr) | 366 while (pCurr) |
367 { | 367 { |
368 xs_dbindex[i++] = pCurr; | 368 xs_sldbi[i++] = pCurr; |
369 pCurr = pCurr->pNext; | 369 pCurr = pCurr->pNext; |
370 } | 370 } |
371 | 371 |
372 /* Sort the indexes */ | 372 /* Sort the indexes */ |
373 qsort(xs_dbindex, xs_dbnodes, sizeof(t_xs_sldb_node *), xs_db_cmp); | 373 qsort(xs_sldbi, xs_sldbn, sizeof(t_xs_sldb_node *), xs_db_cmp); |
374 } | 374 } |
375 | 375 |
376 /* OK */ | 376 /* OK */ |
377 XSDEBUG("init ok.\n"); | 377 XSDEBUG("init ok.\n"); |
378 return 0; | 378 return 0; |
386 { | 386 { |
387 t_xs_sldb_node *pCurr, *pNext; | 387 t_xs_sldb_node *pCurr, *pNext; |
388 | 388 |
389 /* Free the memory allocated for database */ | 389 /* Free the memory allocated for database */ |
390 XSDEBUG("sldb_close()\n"); | 390 XSDEBUG("sldb_close()\n"); |
391 pCurr = xs_database; | 391 pCurr = xs_sldb; |
392 while (pCurr) | 392 while (pCurr) |
393 { | 393 { |
394 pNext = pCurr->pNext; | 394 pNext = pCurr->pNext; |
395 xs_db_node_free(pCurr); | 395 xs_db_node_free(pCurr); |
396 pCurr = pNext; | 396 pCurr = pNext; |
397 } | 397 } |
398 | 398 |
399 xs_database = NULL; | 399 xs_sldb = NULL; |
400 | 400 |
401 /* Free memory allocated for indexes */ | 401 /* Free memory allocated for indexes */ |
402 if (xs_dbindex) | 402 if (xs_sldbi) |
403 { | 403 { |
404 g_free(xs_dbindex); | 404 g_free(xs_sldbi); |
405 xs_dbindex = NULL; | 405 xs_sldbi = NULL; |
406 } | 406 } |
407 } | 407 } |
408 | 408 |
409 | 409 |
410 /* | 410 /* |