Contiki-NG
index.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2010, Swedish Institute of Computer Science
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 * 3. Neither the name of the Institute nor the names of its contributors
14 * may be used to endorse or promote products derived from this software
15 * without specific prior written permission.
16 *
17 * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
18 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20 * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
21 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27 * SUCH DAMAGE.
28 */
29
30/**
31 * \file index.h
32 * \author
33 * Nicolas Tsiftes <nvt@sics.se>
34 */
35
36#ifndef INDEX_H
37#define INDEX_H
38
39#include "relation.h"
40
41typedef enum {
42 INDEX_NONE = 0,
43 INDEX_INLINE = 1,
44 INDEX_MEMHASH = 2,
45 INDEX_MAXHEAP = 3
46} index_type_t;
47
48#define INDEX_READY 0x00
49#define INDEX_LOAD_NEEDED 0x01
50#define INDEX_LOAD_ERROR 0x02
51
52#define INDEX_API_INTERNAL 0x01
53#define INDEX_API_EXTERNAL 0x02
54#define INDEX_API_INLINE 0x04
55#define INDEX_API_COMPLETE 0x08
56#define INDEX_API_RANGE_QUERIES 0x10
57
58struct index_api;
59
60struct index {
61 struct index *next;
62 char descriptor_file[DB_MAX_FILENAME_LENGTH];
63 relation_t *rel;
64 attribute_t *attr;
65 struct index_api *api;
66 void *opaque_data;
67 index_type_t type;
68 uint8_t flags;
69};
70
71typedef struct index index_t;
72
73struct index_iterator {
74 index_t *index;
75 attribute_value_t min_value;
76 attribute_value_t max_value;
77 tuple_id_t next_item_no;
78 tuple_id_t found_items;
79};
80typedef struct index_iterator index_iterator_t;
81
82struct index_api {
83 index_type_t type;
84 uint8_t flags;
85 db_result_t (*create)(index_t *);
86 db_result_t (*destroy)(index_t *);
87 db_result_t (*load)(index_t *);
88 db_result_t (*release)(index_t *);
89 db_result_t (*insert)(index_t *, attribute_value_t *, tuple_id_t);
90 db_result_t (*delete)(index_t *, attribute_value_t *);
91 tuple_id_t (*get_next)(index_iterator_t *);
92};
93
94typedef struct index_api index_api_t;
95
96extern index_api_t index_inline;
97extern index_api_t index_maxheap;
98extern index_api_t index_memhash;
99
100void index_init(void);
101db_result_t index_create(index_type_t, relation_t *, attribute_t *);
102db_result_t index_destroy(index_t *);
103db_result_t index_load(relation_t *, attribute_t *);
104db_result_t index_release(index_t *);
105db_result_t index_insert(index_t *, attribute_value_t *, tuple_id_t);
106db_result_t index_delete(index_t *, attribute_value_t *);
107db_result_t index_get_iterator(index_iterator_t *, index_t *,
108 attribute_value_t *, attribute_value_t *);
109tuple_id_t index_get_next(index_iterator_t *);
110int index_exists(attribute_t *);
111
112#endif /* !INDEX_H */