Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
R
railgun-routing-server
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Locked Files
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Security & Compliance
Security & Compliance
Dependency List
License Compliance
Packages
Packages
List
Container Registry
Analytics
Analytics
CI / CD
Code Review
Insights
Issues
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Railgun
railgun-routing-server
Commits
532045b0
Commit
532045b0
authored
Jan 10, 2026
by
nanamicat
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
clean
parent
10241602
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
11 additions
and
11 deletions
+11
-11
src/data.rs
src/data.rs
+11
-11
No files found.
src/data.rs
View file @
532045b0
use
bincode
::{
Decode
,
Encode
};
use
itertools
::{
EitherOrBoth
,
Itertools
};
use
serde
::{
Deserialize
,
Serialize
};
use
std
::{
collections
::
BTreeMap
,
sync
::
OnceLock
};
use
std
::{
collections
::
BTreeMap
,
fmt
::{
Debug
,
Display
},
sync
::
OnceLock
,
};
use
string_interner
::{
StringInterner
,
Symbol
,
backend
::
StringBackend
};
#[derive(Serialize,
Deserialize,
Clone)]
...
...
@@ -96,7 +100,7 @@ pub struct Database {
}
pub
static
DATABASE
:
std
::
sync
::
LazyLock
<
Database
>
=
std
::
sync
::
LazyLock
::
new
(||
Database
{
routers
:
register
(
load_file
(
"import/data/Router.json"
),
|
r
|
r
.id
.
0
,
|
r
|
r
.name
.clone
(),
&
ROUTER_ID_REGISTRY
),
routers
:
register
(
load_file
(
"import/data/Router.json"
),
|
r
|
r
.id
,
|
r
|
r
.name
.clone
(),
&
ROUTER_ID_REGISTRY
),
gateways
:
load_file
(
"import/data/Gateway.json"
),
gateway_groups
:
load_file
(
"import/data/GatewayGroup.json"
),
regions
:
load_file
(
"import/data/Region.json"
),
...
...
@@ -109,28 +113,24 @@ fn load_file<T: serde::de::DeserializeOwned>(path: &str) -> T {
serde_json
::
from_str
(
&
std
::
fs
::
read_to_string
(
path
)
.unwrap
())
.unwrap
()
}
pub
fn
register
<
T
,
I
,
N
,
S
,
Sym
>
(
mut
data
:
Vec
<
T
>
,
num
:
N
,
str
:
S
,
registry
:
&
OnceLock
<
StringInterner
<
StringBackend
<
Sym
>>>
)
->
Vec
<
T
>
pub
fn
register
<
T
,
N
,
S
,
Sym
>
(
mut
data
:
Vec
<
T
>
,
num
:
N
,
str
:
S
,
registry
:
&
OnceLock
<
StringInterner
<
StringBackend
<
Sym
>>>
)
->
Vec
<
T
>
where
T
:
serde
::
de
::
DeserializeOwned
,
N
:
Fn
(
&
T
)
->
I
,
N
:
Fn
(
&
T
)
->
Sym
,
S
:
Fn
(
&
T
)
->
String
,
I
:
Ord
+
Copy
+
std
::
fmt
::
Display
+
From
<
u8
>
,
std
::
ops
::
RangeInclusive
<
I
>
:
Iterator
<
Item
=
I
>
,
Sym
:
Symbol
+
std
::
fmt
::
Debug
,
Sym
:
Symbol
+
Debug
+
Ord
,
{
data
.sort_by_key
(
&
num
);
let
mut
interner
=
StringInterner
::
<
StringBackend
<
Sym
>>
::
new
();
if
let
Some
(
max_id
)
=
data
.last
()
.map
(
&
num
)
{
for
item
in
(
I
::
from
(
0
)
..=
max_id
)
.merge_join_by
(
data
.iter
(),
|
i
,
r
|
i
.cmp
(
&
num
(
r
)))
{
for
item
in
(
0
..=
max_id
.to_usize
())
.merge_join_by
(
data
.iter
(),
|
i
,
r
|
i
.cmp
(
&
num
(
r
)
.to_usize
(
)))
{
let
name
=
match
item
{
EitherOrBoth
::
Both
(
_
,
r
)
=>
str
(
r
),
EitherOrBoth
::
Left
(
i
)
=>
i
.to_string
(),
EitherOrBoth
::
Right
(
_
)
=>
unreachable!
(),
};
let
symbol
=
interner
.get_or_intern
(
name
);
println!
(
"{:?} = {}"
,
symbol
,
item
.left
()
.unwrap
());
interner
.get_or_intern
(
name
);
}
}
interner
.shrink_to_fit
();
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment