Changeset 2b37be2
- Timestamp:
- Jul 29, 2009, 2:52:36 AM (15 years ago)
- Branches:
- master, release-1.10, release-1.4, release-1.5, release-1.6, release-1.7, release-1.8, release-1.9
- Children:
- e711ca7
- Parents:
- 19cc7b00
- git-author:
- Anders Kaseorg <andersk@mit.edu> (07/29/09 02:32:07)
- git-committer:
- Anders Kaseorg <andersk@mit.edu> (07/29/09 02:52:36)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
dict.c
r7cd5878 r2b37be2 32 32 * Returns 1 if found, else 0. */ 33 33 int _owl_dict_find_pos(owl_dict *d, char *k, int *pos) { 34 int lo, hi, mid, cmp; 35 lo = 0; 36 hi = d->size; 34 int lo = 0, hi = d->size; 37 35 while (lo < hi) { 38 mid = (lo+hi)/2; // lo goes up and we can't hit hi, so no +1 39 cmp = strcmp(k, d->els[mid].k); 40 if (cmp == 0) { 41 lo = hi = mid; 42 } else if (cmp < 0) { 36 int mid = (lo + hi)/2; /* lo goes up and we can't hit hi, so no +1 */ 37 int cmp = strcmp(k, d->els[mid].k); 38 if (cmp < 0) { 43 39 hi = mid; 44 } else { // cmp > 040 } else if (cmp > 0) { 45 41 lo = mid+1; 42 } else { 43 *pos = mid; 44 return 1; 46 45 } 47 46 } 48 47 *pos = lo; 49 return !!(lo < d->size && !strcmp(k, d->els[lo].k));48 return 0; 50 49 } 51 50
Note: See TracChangeset
for help on using the changeset viewer.