Debian Codegraph @

cextern/astrometry.net/bl.inc

raw
1 /*
2 # This file is part of the Astrometry.net suite.
3 # Licensed under a 3-clause BSD style license - see LICENSE
4 */
5
6 #include <assert.h>
7
8 #include "bl.ph"
9
10 /* find the node in which element "n" can be found. */
11 InlineDefine
12 bl_node* find_node(const bl* list, size_t n,
13 size_t* p_nskipped) {
14 bl_node* node;
15 size_t nskipped;
16 if (list->last_access && n >= list->last_access_n) {
17 // take the shortcut!
18 nskipped = list->last_access_n;
19 node = list->last_access;
20 } else {
21 node = list->head;
22 nskipped = 0;
23 }
24
25 for (; node;) {
26 if (n < (nskipped + node->N))
27 break;
28 nskipped += node->N;
29 node = node->next;
30 }
31
32 assert(node);
33
34 if (p_nskipped)
35 *p_nskipped = nskipped;
36
37 return node;
38 }
39
40 InlineDefine
41 void* bl_access(bl* list, size_t n) {
42 void* rtn;
43 bl_node* node;
44 size_t nskipped;
45 node = find_node(list, n, &nskipped);
46 // grab the element.
47 rtn = NODE_CHARDATA(node) + (n - nskipped) * list->datasize;
48 // update the last_access member...
49 list->last_access = node;
50 list->last_access_n = nskipped;
51 return rtn;
52 }
53
54 InlineDefine
55 size_t bl_size(const bl* list) {
56 return list->N;
57 }
58
59
60 InlineDefine
61 size_t sl_size(const sl* list) {
62 return bl_size(list);
63 }
64