[go: up one dir, main page]

File: list.h

package info (click to toggle)
dillo 0.8.3-1
  • links: PTS
  • area: main
  • in suites: sarge
  • size: 3,168 kB
  • ctags: 3,987
  • sloc: ansic: 32,778; sh: 3,401; makefile: 251; perl: 17
file content (49 lines) | stat: -rw-r--r-- 1,078 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
/*
 * Fast list methods
 * Feb 2000  --Jcid
 *
 */

#ifndef __LIST_H__
#define __LIST_H__

/*
 * a_List_resize()
 *
 * Make sure there's space for 'num_items' items within the list
 * (First, allocate an 'alloc_step' sized chunk, after that, double the
 *  list size --to make it faster)
 */
#define a_List_resize(list,num_items,alloc_step) \
   if ( !list ) { \
      list = g_malloc(alloc_step * sizeof((*list))); \
   } \
   if ( num_items >= alloc_step ){ \
      while ( num_items >= alloc_step ) \
         alloc_step <<= 1; \
      list = g_realloc(list, alloc_step * sizeof((*list))); \
   }


/*
 * a_List_add()
 *
 * Make sure there's space for one more item within the list.
 */
#define a_List_add(list,num_items,alloc_step) \
   a_List_resize(list,num_items,alloc_step)


/*
 * a_List_remove()
 *
 * Quickly remove an item from the list
 * ==> We preserve relative position, but not the element index <==
 */
#define a_List_remove(list, item, num_items) \
   if ( list && item < num_items ) { \
      list[item] = list[--num_items]; \
   }


#endif /* __LIST_H__ */