Skip to content

Commit 176a786

Browse files
committed
Add hnsw index
HNSW implementation code from my PR on sdslabs/VortexDB sdslabs/VortexDB#43 Signed-off-by: Arshdeep54 <balarsh535@gmail.com>
1 parent 9ce8d32 commit 176a786

File tree

15 files changed

+1509
-66
lines changed

15 files changed

+1509
-66
lines changed

Cargo.lock

Lines changed: 238 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,8 @@ edition = "2024"
55

66
[dependencies]
77
input_handler = "0.1"
8+
rand = "0.9.2"
9+
serde = {version = "1.0.228" ,features = ["derive"]}
10+
serde_json = "1.0.145"
811
tempfile = "3.21.0"
12+
uuid ={version= "1.19.0",features = ["serde","v4","v5"]}

src/bin/indexium.rs

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
use std::{fs, path::PathBuf};
2+
3+
use indexium::parsing::parse_command;
4+
use indexium::session::IndexSession;
5+
use input_handler::InputHandler;
6+
7+
fn main() {
8+
let mut index_session = IndexSession::new();
9+
10+
let data_dir = PathBuf::from("data");
11+
if !data_dir.exists() {
12+
fs::create_dir(&data_dir).expect("Failed to create data directory");
13+
}
14+
let history_file = data_dir.join("history.txt");
15+
16+
let mut input_handler =
17+
InputHandler::with_history_file(history_file).expect("Failed to initialize input handler");
18+
19+
while let Ok(line) = input_handler.readline("indexium> ") {
20+
if line.eq_ignore_ascii_case("exit") {
21+
break;
22+
}
23+
parse_command(&mut index_session, &line);
24+
}
25+
}

src/btree/node.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -215,10 +215,10 @@ impl Node {
215215

216216
child.items.insert(0, parent_item);
217217

218-
if !sibling.is_leaf() {
219-
if let Some(last_child) = sibling.children.pop() {
220-
child.children.insert(0, last_child);
221-
}
218+
if !sibling.is_leaf()
219+
&& let Some(last_child) = sibling.children.pop()
220+
{
221+
child.children.insert(0, last_child);
222222
}
223223

224224
sibling.num_items -= 1;
@@ -243,11 +243,11 @@ impl Node {
243243

244244
child.items.push(parent_item);
245245

246-
if !sibling.is_leaf() {
247-
if let Some(first_child) = sibling.children.first().cloned() {
248-
child.children.push(Box::new(*first_child));
249-
sibling.children.remove(0);
250-
}
246+
if !sibling.is_leaf()
247+
&& let Some(first_child) = sibling.children.first().cloned()
248+
{
249+
child.children.push(Box::new(*first_child));
250+
sibling.children.remove(0);
251251
}
252252

253253
sibling.num_items -= 1;

src/btree/utils.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,10 @@ pub struct Visualizer {
1010

1111
impl Visualizer {
1212
pub fn new(path: &str) -> Self {
13-
if let Some(parent) = Path::new(path).parent() {
14-
if !parent.exists() {
15-
fs::create_dir_all(parent).expect("Failed to create visualization directory");
16-
}
13+
if let Some(parent) = Path::new(path).parent()
14+
&& !parent.exists()
15+
{
16+
fs::create_dir_all(parent).expect("Failed to create visualization directory");
1717
}
1818

1919
Visualizer {

0 commit comments

Comments
 (0)