Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
C
commoncrawl_graph
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Stephen D
commoncrawl_graph
Commits
5c14ebd1
Commit
5c14ebd1
authored
5 months ago
by
Stephen D
Browse files
Options
Downloads
Patches
Plain Diff
name from id binary search
parent
7243e0a5
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
src/bin/import.rs
+1
-1
1 addition, 1 deletion
src/bin/import.rs
src/bin/serve.rs
+3
-1
3 additions, 1 deletion
src/bin/serve.rs
src/graph.rs
+29
-0
29 additions, 0 deletions
src/graph.rs
with
33 additions
and
2 deletions
src/bin/import.rs
+
1
−
1
View file @
5c14ebd1
...
...
@@ -119,7 +119,7 @@ async fn save_nodes(mut rx: Receiver<String>) -> anyhow::Result<()> {
.into_iter
()
.map
(|(
id
,
offset
)|
{
// An allocation in here is gross
let
mut
x
=
id
.to_le_bytes
()
.to_vec
();
let
mut
x
=
id
.to_le_bytes
()
.to_vec
();
// TODO no reason to put id here?
x
.extend
(
offset
.to_le_bytes
());
x
...
...
This diff is collapsed.
Click to expand it.
src/bin/serve.rs
+
3
−
1
View file @
5c14ebd1
...
...
@@ -4,7 +4,9 @@ use commoncrawl_graph::graph::NodeReader;
async
fn
main
()
->
anyhow
::
Result
<
()
>
{
let
mut
nr
=
NodeReader
::
new
()
.await
?
;
nr
.id_from_name
(
"com.scd31"
)
.await
?
;
let
id
=
nr
.id_from_name
(
"com.scd31"
)
.await
?
.unwrap
();
let
host
=
nr
.name_from_id
(
id
)
.await
?
;
println!
(
"{:?}"
,
host
);
Ok
(())
}
This diff is collapsed.
Click to expand it.
src/graph.rs
+
29
−
0
View file @
5c14ebd1
...
...
@@ -59,4 +59,33 @@ impl NodeReader {
}
}
}
pub
async
fn
name_from_id
(
&
mut
self
,
id
:
u32
)
->
anyhow
::
Result
<
Option
<
String
>>
{
let
mut
min
=
0
;
let
mut
max
=
self
.num_nodes
;
loop
{
let
cur
=
(
max
+
min
)
/
2
+
1
;
self
.id_index
.seek
(
SeekFrom
::
Start
(
cur
*
12
+
4
))
.await
?
;
let
offset
=
self
.id_index
.read_u64_le
()
.await
?
;
self
.nodes
.seek
(
SeekFrom
::
Start
(
offset
.into
()))
.await
?
;
let
host_id
=
self
.nodes
.read_u32_le
()
.await
?
;
let
host
=
BufReader
::
new
(
&
mut
self
.nodes
)
.lines
()
.next_line
()
.await
?
.context
(
"Missing line"
)
?
;
let
c
=
id
.cmp
(
&
host_id
);
match
c
{
Ordering
::
Less
=>
max
=
cur
,
Ordering
::
Equal
=>
{
return
Ok
(
Some
(
host
));
}
Ordering
::
Greater
=>
min
=
cur
,
}
}
}
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment