- Timestamp:
- Feb 6, 2007, 6:05:13 PM (18 years ago)
- Branches:
- master, barnowl_perlaim, debian, release-1.10, release-1.4, release-1.5, release-1.6, release-1.7, release-1.8, release-1.9
- Children:
- 7a20e4c
- Parents:
- 2566560
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
view.c
rf1e629d r801b7ac 97 97 int owl_view_get_nearest_to_msgid(owl_view *v, int targetid) 98 98 { 99 int i, bestdist=-1, bestpos=0, curid, curdist;99 int first, last, mid = 0, max, bestdist, curid = 0; 100 100 101 for (i=0; i<owl_view_get_size(v); i++) { 102 curid = owl_message_get_id(owl_view_get_element(v, i)); 103 curdist = abs(targetid-curid); 104 if (bestdist<0 || curdist<bestdist) { 105 bestdist = curdist; 106 bestpos = i; 101 first = 0; 102 last = max = owl_view_get_size(v) - 1; 103 while (first <= last) { 104 mid = (first + last) / 2; 105 curid = owl_message_get_id(owl_view_get_element(v, mid)); 106 if (curid == targetid) { 107 return(mid); 108 } else if (curid < targetid) { 109 first = mid + 1; 110 } else { 111 last = mid - 1; 107 112 } 108 113 } 109 return (bestpos); 114 bestdist = abs(targetid-curid); 115 if (curid < targetid && mid+1 < max) { 116 curid = owl_message_get_id(owl_view_get_element(v, mid+1)); 117 mid = (bestdist < abs(targetid-curid)) ? mid : mid+1; 118 } 119 else if (curid > targetid && mid-1 >= 0) { 120 curid = owl_message_get_id(owl_view_get_element(v, mid-1)); 121 mid = (bestdist < abs(targetid-curid)) ? mid : mid-1; 122 } 123 return mid; 110 124 } 111 125
Note: See TracChangeset
for help on using the changeset viewer.