-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathordered_array.h
More file actions
63 lines (51 loc) · 1.43 KB
/
ordered_array.h
File metadata and controls
63 lines (51 loc) · 1.43 KB
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
/**
* ordered_array.h - Interface for creating, inserting and deleting
* from ordered arrays.
* @version $Id$
*/
#ifndef ORDERED_ARRAY_H
#define ORDERED_ARRAY_H
#include "common.h"
/**
* This array is insertion sorted - it always remains in a sorted state (between calls).
* It can store anything that can be cast to a void* -- so a u32int, or any pointer.
*/
typedef void* type_t;
/**
* A predicate should return nonzero if the first argument is less than the second. Else
* it should return zero.
*/
typedef s8int (*lessthan_predicate_t)(type_t,type_t);
typedef struct
{
type_t *array;
u32int size;
u32int max_size;
lessthan_predicate_t less_than;
} ordered_array_t;
/**
* A standard less than predicate.
*/
s8int standard_lessthan_predicate(type_t a, type_t b);
/**
* Create an ordered array.
*/
ordered_array_t create_ordered_array(u32int max_size, lessthan_predicate_t less_than);
ordered_array_t place_ordered_array(void *addr, u32int max_size, lessthan_predicate_t less_than);
/**
* Destroy an ordered array.
*/
void destroy_ordered_array(ordered_array_t *array);
/**
* Add an item into the array.
*/
void insert_ordered_array(type_t item, ordered_array_t *array);
/**
* Lookup the item at index i.
*/
type_t lookup_ordered_array(u32int i, ordered_array_t *array);
/**
* Deletes the item at location i from the array.
*/
void remove_ordered_array(u32int i, ordered_array_t *array);
#endif // ORDERED_ARRAY_H