Skip to content
Snippets Groups Projects
Commit f812a353 authored by Stephen D's avatar Stephen D
Browse files

this is definitely stupid overkill. and reads are kind of slow anyway. I am reverted to postgres

parent dfca76f2
No related branches found
No related tags found
No related merge requests found
......@@ -5,7 +5,7 @@ async fn main() -> anyhow::Result<()> {
let mut nr = NodeReader::new().await?;
let mut er = EdgeReader::new().await?;
let id = nr.id_from_name("com.scd31.git").await?.unwrap();
let id = nr.id_from_name("com.scd31").await?.unwrap();
for e in er.get_nodes_to(id).await? {
dbg!(&e);
......
......@@ -44,27 +44,29 @@ impl NodeReader {
// binary search for name
let mut min = 0;
let mut max = self.num_nodes;
let mut max = self.num_nodes - 1;
loop {
let cur = (max + min) / 2 + 1;
while max >= min {
let cur = (max + min) / 2;
let node = self.get_node_from_name_idx(cur).await?;
let c = name.cmp(&node.name);
match c {
Ordering::Less => max = cur,
Ordering::Less => max = cur - 1,
Ordering::Equal => {
return Ok(Some(node.id));
}
Ordering::Greater => min = cur,
Ordering::Greater => min = cur + 1,
}
}
Ok(None)
}
pub async fn name_from_id(&mut self, id: u32) -> anyhow::Result<Option<String>> {
let mut min = 0;
let mut max = self.num_nodes;
let mut max = self.num_nodes - 1;
loop {
let cur = (max + min) / 2;
......@@ -82,11 +84,11 @@ impl NodeReader {
let c = id.cmp(&host_id);
match c {
Ordering::Less => max = cur,
Ordering::Less => max = cur - 1,
Ordering::Equal => {
return Ok(Some(host));
}
Ordering::Greater => min = cur,
Ordering::Greater => min = cur + 1,
}
if max == min {
......@@ -154,40 +156,40 @@ impl EdgeReader {
pub async fn get_nodes_from(&mut self, from: u32) -> anyhow::Result<Vec<Edge>> {
let mut min = 0;
let mut max = self.num_edges;
let mut max = self.num_edges - 1;
loop {
let cur = (max + min) / 2 + 1;
let cur = (max + min) / 2;
let edge = self.get_edge_from_from_idx(cur).await?;
let c = from.cmp(&edge.from);
match c {
Ordering::Less => max = cur,
Ordering::Less => max = cur - 1,
Ordering::Equal => {
return self.get_all_consecutive_matching_from(cur, from).await;
}
Ordering::Greater => min = cur,
Ordering::Greater => min = cur + 1,
}
}
}
pub async fn get_nodes_to(&mut self, to: u32) -> anyhow::Result<Vec<Edge>> {
let mut min = 0;
let mut max = self.num_edges;
let mut max = self.num_edges - 1;
loop {
let cur = (max + min) / 2 + 1;
let cur = (max + min) / 2;
let edge = self.get_edge_from_to_idx(cur).await?;
let c = to.cmp(&edge.to);
match c {
Ordering::Less => max = cur,
Ordering::Less => max = cur - 1,
Ordering::Equal => {
return self.get_all_consecutive_matching_to(cur, to).await;
}
Ordering::Greater => min = cur,
Ordering::Greater => min = cur + 1,
}
}
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment