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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
//! Data models for graph entities.
//!
//! This module defines the core data structures used to represent
//! nodes, edges, and their properties in the Sombra graph database.
//!
//! # Key Types
//!
//! - [`Node`] - Represents a graph node with labels and properties
//! - [`Edge`] - Represents a directed edge between nodes
//! - [`PropertyValue`] - Enum for different property value types
//! - [`NodeId`] / [`EdgeId`] - Unique identifiers for nodes and edges
//!
//! # Examples
//!
//! ```rust
//! use sombra::model::{Node, Edge, PropertyValue};
//! use std::collections::BTreeMap;
//!
//! // Create a node with properties
//! let mut properties = BTreeMap::new();
//! properties.insert("name".to_string(), PropertyValue::String("Alice".to_string()));
//!
//! let mut node = Node::new(1);
//! node.labels.push("Person".to_string());
//! node.properties = properties;
//!
//! // Create an edge
//! let edge = Edge::new(1, 1, 2, "KNOWS");
//! ```
use Ordering;
use BTreeMap;
/// Unique identifier for nodes in the graph.
pub type NodeId = u64;
/// Unique identifier for edges in the graph.
pub type EdgeId = u64;
/// Special value indicating no edge (null edge ID).
pub const NULL_EDGE_ID: EdgeId = 0;
/// Special value indicating no node (null node ID).
pub const NULL_NODE_ID: NodeId = 0;
/// Direction for traversing edges in the graph.
/// Represents a property value that can be stored on nodes and edges.
///
/// Property values support various data types commonly used in graph databases.
/// Only Bool, Int, and String values can be indexed for fast lookups.
///
/// # Examples
///
/// ```rust
/// use sombra::model::PropertyValue;
///
/// let name = PropertyValue::String("Alice".to_string());
/// let age = PropertyValue::Int(30);
/// let active = PropertyValue::Bool(true);
/// let score = PropertyValue::Float(95.5);
/// let data = PropertyValue::Bytes(vec![1, 2, 3]);
/// ```
/// Represents a node in the graph.
///
/// Nodes are the primary entities in a graph database and can have
/// multiple labels and properties. Nodes are connected by edges.
///
/// # Fields
///
/// * `id` - Unique identifier for the node
/// * `labels` - List of labels categorizing the node
/// * `properties` - Key-value pairs storing node attributes
/// * `first_outgoing_edge_id` - Head of the outgoing edge linked list
/// * `first_incoming_edge_id` - Head of the incoming edge linked list
///
/// # Examples
///
/// ```rust
/// use sombra::model::{Node, PropertyValue};
/// use std::collections::BTreeMap;
///
/// let mut properties = BTreeMap::new();
/// properties.insert("name".to_string(), PropertyValue::String("Alice".to_string()));
/// properties.insert("age".to_string(), PropertyValue::Int(30));
///
/// let mut node = Node::new(1);
/// node.labels.push("Person".to_string());
/// node.properties = properties;
/// ```
/// Represents a directed edge connecting two nodes in the graph.
///
/// Edges represent relationships between nodes and can have a type
/// and properties. Edges are directed from a source node to a target node.
///
/// # Fields
///
/// * `id` - Unique identifier for the edge
/// * `source_node_id` - ID of the source (origin) node
/// * `target_node_id` - ID of the target (destination) node
/// * `type_name` - Type/name of the relationship
/// * `properties` - Key-value pairs storing edge attributes
/// * `next_outgoing_edge_id` - Next edge from source node
/// * `next_incoming_edge_id` - Next edge to target node
///
/// # Examples
///
/// ```rust
/// use sombra::model::{Edge, PropertyValue};
/// use std::collections::BTreeMap;
///
/// let mut properties = BTreeMap::new();
/// properties.insert("since".to_string(), PropertyValue::Int(2020));
///
/// let edge = Edge::new(1, 1, 2, "KNOWS");
/// // Or with properties:
/// let mut edge_with_props = Edge::new(2, 1, 2, "WORKS_WITH");
/// edge_with_props.properties = properties;
/// ```