Mercurial > repos > rhope
comparison dict.c @ 3:94c885692eb5
Partial set of fixes and enhancements from Linux box
author | Mike Pavone <pavone@retrodev.com> |
---|---|
date | Wed, 29 Apr 2009 03:21:23 -0400 |
parents | 76568becd6d6 |
children |
comparison
equal
deleted
inserted
replaced
2:73e978d590c7 | 3:94c885692eb5 |
---|---|
340 ternary_node * nodes; | 340 ternary_node * nodes; |
341 ternary_node * current = dict->nodes; | 341 ternary_node * current = dict->nodes; |
342 ternary_node * decision = NULL; | 342 ternary_node * decision = NULL; |
343 int decision_key_size; | 343 int decision_key_size; |
344 BOOL next_flag = FALSE; | 344 BOOL next_flag = FALSE; |
345 BOOL this_flag = FALSE; | |
345 nodes = current; | 346 nodes = current; |
346 | 347 |
347 if(dict->num_nodes <= 0) | 348 if(dict->num_nodes <= 0) |
348 { | 349 { |
349 release_ref(inputlist[1]); | 350 release_ref(inputlist[1]); |
357 while(current >= nodes) | 358 while(current >= nodes) |
358 { | 359 { |
359 if(old_key[i] == current->letter) | 360 if(old_key[i] == current->letter) |
360 if(i == (old_key_len)) | 361 if(i == (old_key_len)) |
361 { | 362 { |
362 if(current->left >= 0) | 363 /*if(current->left >= 0) |
363 { | 364 { |
364 current = nodes + current->left; | 365 current = nodes + current->left; |
365 break; | 366 break; |
366 } | 367 } |
367 else if(current->next >= 0) | 368 else */if(current->next >= 0) |
368 { | 369 { |
369 APPEND_KEY_STORE(key, key_store, key_size, current->letter); | 370 APPEND_KEY_STORE(key, key_store, key_size, current->letter); |
370 current = nodes + current->next; | 371 current = nodes + current->next; |
371 break; | 372 break; |
372 } | 373 } |
383 current = decision; | 384 current = decision; |
384 if(next_flag) | 385 if(next_flag) |
385 { | 386 { |
386 APPEND_KEY_STORE(key, key_store, key_size, current->letter); | 387 APPEND_KEY_STORE(key, key_store, key_size, current->letter); |
387 current = nodes + current->next; | 388 current = nodes + current->next; |
389 } | |
390 else if(this_flag) | |
391 { | |
392 APPEND_KEY_STORE(key, key_store, key_size, current->letter); | |
393 APPEND_KEY_STORE(key, key_store, key_size, '\0'); | |
394 release_ref(inputlist[0]); | |
395 release_ref(inputlist[1]); | |
396 inputlist[1] = NULL; | |
397 inputlist[0] = new_datum(BUILTIN_TYPE_STRING, 2, 0, worker_entry->instance->def->program); | |
398 inputlist[0]->union_type = 1; | |
399 inputlist[0]->c.generic.data = key; | |
400 inputlist[0]->c.generic.len = key_size; | |
401 return 0; | |
388 } | 402 } |
389 break; | 403 break; |
390 } | 404 } |
391 else | 405 else |
392 { | 406 { |
403 if(current->right >= 0) | 417 if(current->right >= 0) |
404 { | 418 { |
405 decision = nodes + current->right; | 419 decision = nodes + current->right; |
406 decision_key_size = key_size; | 420 decision_key_size = key_size; |
407 next_flag = FALSE; | 421 next_flag = FALSE; |
422 this_flag = FALSE; | |
408 } | 423 } |
409 APPEND_KEY_STORE(key, key_store, key_size, current->letter); | 424 APPEND_KEY_STORE(key, key_store, key_size, current->letter); |
410 ++i; | 425 ++i; |
411 current = nodes + current->next; | 426 current = nodes + current->next; |
412 } | 427 } |
413 else if(old_key[i] > current->letter) | 428 else if(old_key[i] > current->letter) |
414 current = nodes + current->right; | 429 current = nodes + current->right; |
415 else | 430 else |
416 { | 431 { |
417 if(current->next >= 0) | 432 //Hmm, what do I do here if there's a payload at this location? |
433 if(current->next >= 0 || current->payload) | |
418 { | 434 { |
419 //APPEND_KEY_STORE(key, key_store, key_size, current->letter); | 435 //APPEND_KEY_STORE(key, key_store, key_size, current->letter); |
420 decision = current;//nodes + current->next; | 436 decision = current;//nodes + current->next; |
421 decision_key_size = key_size; | 437 decision_key_size = key_size; |
422 next_flag = TRUE; | 438 if(current->payload) |
439 { | |
440 next_flag = FALSE; | |
441 this_flag = TRUE; | |
442 } else { | |
443 next_flag = TRUE; | |
444 this_flag = FALSE; | |
445 } | |
423 } | 446 } |
424 else if(current->right >= 0) | 447 else if(current->right >= 0) |
425 { | 448 { |
426 decision = nodes + current->right; | 449 decision = nodes + current->right; |
427 decision_key_size = key_size; | 450 decision_key_size = key_size; |
428 next_flag = FALSE; | 451 next_flag = FALSE; |
452 this_flag = FALSE; | |
429 } | 453 } |
430 current = nodes + current->left; | 454 current = nodes + current->left; |
431 } | 455 } |
432 } | 456 } |
433 if(current < nodes) | 457 if(current < nodes) |