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
32  * .
33  * \author
34  * Nicolas Tsiftes <nvt@sics.se>
35  */
36 
37 #ifndef INDEX_H
38 #define INDEX_H
39 
40 #include "relation.h"
41 
42 typedef enum {
43  INDEX_NONE = 0,
44  INDEX_INLINE = 1,
45  INDEX_MEMHASH = 2,
46  INDEX_MAXHEAP = 3
47 } index_type_t;
48 
49 #define INDEX_READY 0x00
50 #define INDEX_LOAD_NEEDED 0x01
51 #define INDEX_LOAD_ERROR 0x02
52 
53 #define INDEX_API_INTERNAL 0x01
54 #define INDEX_API_EXTERNAL 0x02
55 #define INDEX_API_INLINE 0x04
56 #define INDEX_API_COMPLETE 0x08
57 #define INDEX_API_RANGE_QUERIES 0x10
58 
59 struct index_api;
60 
61 struct index {
62  struct index *next;
63  char descriptor_file[DB_MAX_FILENAME_LENGTH];
64  relation_t *rel;
65  attribute_t *attr;
66  struct index_api *api;
67  void *opaque_data;
68  index_type_t type;
69  uint8_t flags;
70 };
71 
72 typedef struct index index_t;
73 
74 struct index_iterator {
75  index_t *index;
76  attribute_value_t min_value;
77  attribute_value_t max_value;
78  tuple_id_t next_item_no;
79  tuple_id_t found_items;
80 };
81 typedef struct index_iterator index_iterator_t;
82 
83 struct index_api {
84  index_type_t type;
85  uint8_t flags;
86  db_result_t (*create)(index_t *);
87  db_result_t (*destroy)(index_t *);
88  db_result_t (*load)(index_t *);
89  db_result_t (*release)(index_t *);
90  db_result_t (*insert)(index_t *, attribute_value_t *, tuple_id_t);
91  db_result_t (*delete)(index_t *, attribute_value_t *);
92  tuple_id_t (*get_next)(index_iterator_t *);
93 };
94 
95 typedef struct index_api index_api_t;
96 
97 extern index_api_t index_inline;
98 extern index_api_t index_maxheap;
99 extern index_api_t index_memhash;
100 
101 void index_init(void);
102 db_result_t index_create(index_type_t, relation_t *, attribute_t *);
103 db_result_t index_destroy(index_t *);
104 db_result_t index_load(relation_t *, attribute_t *);
105 db_result_t index_release(index_t *);
106 db_result_t index_insert(index_t *, attribute_value_t *, tuple_id_t);
107 db_result_t index_delete(index_t *, attribute_value_t *);
108 db_result_t index_get_iterator(index_iterator_t *, index_t *,
109  attribute_value_t *, attribute_value_t *);
110 tuple_id_t index_get_next(index_iterator_t *);
111 int index_exists(attribute_t *);
112 
113 #endif /* !INDEX_H */