46 static int index_find(
mxml_index_t *ind,
const char *element,
48 static void index_sort(
mxml_index_t *ind,
int left,
int right);
127 printf(
"mxmlIndexFind(ind=%p, element=\"%s\", value=\"%s\")\n",
128 ind, element ? element :
"(null)", value ? value :
"(null)");
135 if (!ind || (!ind->
attr && value))
138 puts(
" returning NULL...");
139 printf(
" ind->attr=\"%s\"\n", ind->
attr ? ind->
attr :
"(null)");
150 if (!element && !value)
160 puts(
" returning NULL...");
181 printf(
" find first time, num_nodes=%d...\n", ind->
num_nodes);
184 while ((last - first) > 1)
186 current = (first + last) / 2;
189 printf(
" first=%d, last=%d, current=%d\n", first, last, current);
192 if ((diff = index_find(ind, element, value, ind->
nodes[current])) == 0)
202 while (current > 0 &&
203 !index_find(ind, element, value, ind->
nodes[current - 1]))
207 printf(
" returning first match=%d\n", current);
216 return (ind->
nodes[current]);
224 printf(
" diff=%d\n", diff);
232 for (current = first; current <= last; current ++)
233 if (!index_find(ind, element, value, ind->
nodes[current]))
240 printf(
" returning only match %d...\n", current);
245 return (ind->
nodes[current]);
255 puts(
" returning NULL...");
268 printf(
" returning next match %d...\n", ind->
cur_node);
281 puts(
" returning NULL...");
313 printf(
"mxmlIndexNew(node=%p, element=\"%s\", attr=\"%s\")\n",
314 node, element ? element :
"(null)", attr ? attr :
"(null)");
326 mxml_error(
"Unable to allocate %d bytes for index - %s",
334 if (!element && !attr)
354 mxml_error(
"Unable to allocate %d bytes for index: %s",
380 printf(
"%d node(s) in index.\n\n", ind->
num_nodes);
384 printf(
"Node Address Element %s\n", attr);
385 puts(
"-------- -------- -------------- ------------------------------");
388 printf(
"%8d %-8p %-14.14s %s\n", i, ind->
nodes[i],
394 puts(
"Node Address Element");
395 puts(
"-------- -------- --------------");
398 printf(
"%8d %-8p %s\n", i, ind->
nodes[i],
414 puts(
"After sorting:\n");
418 printf(
"Node Address Element %s\n", attr);
419 puts(
"-------- -------- -------------- ------------------------------");
422 printf(
"%8d %-8p %-14.14s %s\n", i, ind->
nodes[i],
428 puts(
"Node Address Element");
429 puts(
"-------- -------- --------------");
432 printf(
"%8d %-8p %s\n", i, ind->
nodes[i],
460 printf(
"mxmlIndexReset(ind=%p)\n", ind);
481 return (ind->
nodes[0]);
594 pivot = ind->
nodes[left];
596 for (templ = left, tempr = right; templ < tempr;)
602 while ((templ < right) &&
603 index_compare(ind, ind->
nodes[templ], pivot) <= 0)
610 while ((tempr > left) &&
611 index_compare(ind, ind->
nodes[tempr], pivot) > 0)
620 temp = ind->
nodes[templ];
622 ind->
nodes[tempr] = temp;
631 if (index_compare(ind, pivot, ind->
nodes[tempr]) > 0)
634 ind->
nodes[tempr] = pivot;
641 if (left < (tempr - 1))
642 index_sort(ind, left, tempr - 1);
644 while (right > (left = tempr + 1));