-
Notifications
You must be signed in to change notification settings - Fork 0
/
ordered_array.h
52 lines (40 loc) · 1.48 KB
/
ordered_array.h
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
// ordered_array.h -- Interface for creating, insterting and deleting
// from ordered_arrays.
// Written fro JamesM's kernel developement tutorials.
#ifndef ORDERED_ARRAY_H
#define ORDERED_ARRAY_H
#include "common.h"
/**
This array is insertion sorted - it always remains in a sorted state.
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);
// Creates 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