Changeset dab82f29 for messagelist.c
- Timestamp:
- Mar 28, 2009, 5:00:34 PM (17 years ago)
- Branches:
- owl
- Children:
- 4de643d
- Parents:
- 5189631
- File:
-
- 1 edited
-
messagelist.c (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
messagelist.c
rbd3f232 rdab82f29 1 /* Copyright (c) 2002,2003,2004,2009 James M. Kretchmar 2 * 3 * This file is part of Owl. 4 * 5 * Owl is free software: you can redistribute it and/or modify 6 * it under the terms of the GNU General Public License as published by 7 * the Free Software Foundation, either version 3 of the License, or 8 * (at your option) any later version. 9 * 10 * Owl is distributed in the hope that it will be useful, 11 * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 * GNU General Public License for more details. 14 * 15 * You should have received a copy of the GNU General Public License 16 * along with Owl. If not, see <http://www.gnu.org/licenses/>. 17 * 18 * --------------------------------------------------------------- 19 * 20 * As of Owl version 2.1.12 there are patches contributed by 21 * developers of the the branched BarnOwl project, Copyright (c) 22 * 2006-2008 The BarnOwl Developers. All rights reserved. 23 */ 24 1 25 #include "owl.h" 2 26 #include <stdlib.h> … … 21 45 } 22 46 23 owl_message *owl_messagelist_get_by_id(owl_messagelist *ml, int id)47 owl_message *owl_messagelist_get_by_id(owl_messagelist *ml, int target_id) 24 48 { 25 49 /* return the message with id == 'id'. If it doesn't exist return NULL. */ 26 /* we could make this much more efficient at some point */ 27 int i, j; 50 int first, last, mid, msg_id; 28 51 owl_message *m; 29 52 30 j=owl_list_get_size(&(ml->list)); 31 for (i=0; i<j; i++) { 32 m=owl_list_get_element(&(ml->list), i); 33 if (owl_message_get_id(m)==id) return(m); 34 35 /* the message id's have to be sequential. If we've passed the 36 one we're looking for just bail */ 37 if (owl_message_get_id(m) > id) return(NULL); 53 first = 0; 54 last = owl_list_get_size(&(ml->list)) - 1; 55 while (first <= last) { 56 mid = (first + last) / 2; 57 m = owl_list_get_element(&(ml->list), mid); 58 msg_id = owl_message_get_id(m); 59 if (msg_id == target_id) { 60 return(m); 61 } else if (msg_id < target_id) { 62 first = mid + 1; 63 } else { 64 last = mid - 1; 65 } 38 66 } 39 67 return(NULL);
Note: See TracChangeset
for help on using the changeset viewer.
