-
Notifications
You must be signed in to change notification settings - Fork 3
/
judyarr.h
91 lines (74 loc) · 3.01 KB
/
judyarr.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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
//-< JUDY.H >--------------------------------------------------------*--------*
// POST++ Version 1.0 (c) 1998 GARRET * ? *
// (Persistent Object Storage) * /\| *
// * / \ *
// Created: 15-Mar-2009 K.A. Knizhnik * / [] \ *
// Last update: 15-Mar-2009 K.A. Knizhnik * GARRET *
//-------------------------------------------------------------------*--------*
// Judy array interface
//-------------------------------------------------------------------*--------*
#ifndef __JUDYARR_H__
#define __JUDYARR_H__
#include "object.h"
BEGIN_POST_NAMESPACE
template<class Index, class Value, class Position>
class POST_DLL_ENTRY judy_array : public object {
private:
void* root;
public:
/**
* Get element at specified index
* @param index index in the array
* @return element value
*/
Value get(Index index);
/**
* Set element at specified index
* @param index array element index
* @param value array element value
* @return previous array element value
*/
Value set(Index index, Value value);
/**
* Put element at specified index
* @param index array element index
* @return true if element was successfully deleted, false if it is not present in array
*/
bool remove(Index index);
/**
* Search (inclusive) for the first index present that is equal to or greater than the passed index.
* @param index in: index to start search, out: index of the first element
* @return first element value or 0 if array is empty
*/
Value first(Position index);
/**
* Search (inclusive) for the last index present that is equal to or less than the passed index.
* @param index in: index to start search, out: index of the last element
* @return last element value or 0 if array is empty
*/
Value last(Position index);
/**
* Search (exclusive) for the next index present that is greater than the passed index.
* @param index in: index to continue search, out: index of the next element
* @return next element value or 0 if end of array is reached
*/
Value next(Position index);
/**
* Search (exclusive) for the previous index present that is less than the passed index.
* @param index in: index to continue search, out: index of the previous element
* @return next element value or 0 if beginning of array is reached
*/
Value prev(Position index);
judy_array() {
root = 0;
}
~judy_array();
static judy_array* create() {
return (judy_array*)post_raw_object::create(*storage::get_current_storage(), sizeof(judy_array));
}
};
typedef judy_array<const char*,object*,char*> dictionary;
typedef judy_array<long,object*,long&> sparse_array;
typedef judy_array<long,bool,long&> bit_array;
END_POST_NAMESPACE
#endif