Skip to content

Commit 5c29b2a

Browse files
committed
Ported to new sux
1 parent ce632cd commit 5c29b2a

File tree

11 files changed

+48
-42
lines changed

11 files changed

+48
-42
lines changed

Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@ anyhow = { version = "1.0.79", features=["backtrace"]}
2323
java-properties = "2.0.0"
2424
mmap-rs = "0.6.1"
2525
num_cpus = "1.16.0"
26-
epserde = "0.4.0"
27-
sux = "0.3.1"
26+
epserde = "0.6.1"
27+
sux = "0.4.0"
2828
dsi-bitstream = "0.4.0"
2929
dsi-progress-logger = "0.2.4"
3030
log = "0.4.20"

src/algo/llp/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ pub fn layered_label_propagation<R: RandomAccessGraph + Sync>(
9393
const IMPROV_WINDOW: usize = 10;
9494
let num_nodes = sym_graph.num_nodes();
9595
let chunk_size = chunk_size.unwrap_or(1_000_000);
96-
let granularity = granularity.unwrap_or(((sym_graph.num_arcs() >> 9) as usize).max(1024));
96+
let granularity = granularity.unwrap_or(Ord::max((sym_graph.num_arcs() >> 9) as usize, 1024));
9797

9898
// init the permutation with the indices
9999
let mut update_perm = (0..num_nodes).collect::<Vec<_>>();
@@ -122,7 +122,7 @@ pub fn layered_label_propagation<R: RandomAccessGraph + Sync>(
122122
// init the iteration progress logger
123123
let mut iter_pl = progress_logger!(item_name = "update");
124124

125-
let hash_map_init = (sym_graph.num_arcs() / sym_graph.num_nodes() as u64).max(16) as usize;
125+
let hash_map_init = Ord::max(sym_graph.num_arcs() / sym_graph.num_nodes() as u64, 16) as usize;
126126

127127
// init the update progress logger
128128
let mut update_pl = progress_logger!(item_name = "node", local_speed = true);

src/cli/build/dcf.rs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -88,18 +88,22 @@ where
8888
let mut iter = seq_graph.offset_deg_iter();
8989
let mut cumul_deg = 0;
9090

91-
efb.push(0)?;
91+
efb.push(0);
9292
for (_new_offset, degree) in iter.by_ref() {
9393
cumul_deg += degree;
9494
// write where
95-
efb.push(cumul_deg as _).context("Could not write gamma")?;
95+
efb.push(cumul_deg as _);
9696
// decode the next nodes so we know where the next node_id starts
9797
pl.light_update();
9898
}
9999
pl.done();
100100

101101
let ef = efb.build();
102-
let ef: DCF = ef.convert_to().unwrap();
102+
let ef: DCF = unsafe {
103+
ef.map_high_bits(|bits| {
104+
SelectZeroAdaptConst::<_, _, 12, 4>::new(SelectAdaptConst::<_, _, 12, 4>::new(bits))
105+
})
106+
};
103107

104108
info!("Writing to disk...");
105109

src/cli/build/ef.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ where
8989
for _node_id in 0..num_nodes {
9090
// write where
9191
offset += reader.read_gamma().context("Could not read gamma")?;
92-
efb.push(offset as _).context("Could not write offset")?;
92+
efb.push(offset as _);
9393
// decode the next nodes so we know where the next node_id starts
9494
pl.light_update();
9595
}
@@ -98,7 +98,8 @@ where
9898
let mut pl = ProgressLogger::default();
9999
pl.display_memory(true);
100100
pl.start("Building the Index over the ones in the high-bits...");
101-
let ef: EF = ef.convert_to().unwrap();
101+
let ef: EF =
102+
unsafe { ef.map_high_bits(|bits| SelectAdaptConst::<_, _, 12, 4>::new(bits)) };
102103
pl.done();
103104

104105
let mut pl = ProgressLogger::default();
@@ -167,7 +168,7 @@ where
167168
for _node_id in 0..num_nodes + 1 {
168169
// write where
169170
offset += reader.read_gamma().context("Could not read gamma")?;
170-
efb.push(offset as _).context("Could not write gamma")?;
171+
efb.push(offset as _);
171172
// decode the next nodes so we know where the next node_id starts
172173
pl.light_update();
173174
}
@@ -184,12 +185,11 @@ where
184185
let mut iter = seq_graph.offset_deg_iter();
185186
for (new_offset, _degree) in iter.by_ref() {
186187
// write where
187-
efb.push(new_offset as _).context("Could not write gamma")?;
188+
efb.push(new_offset as _);
188189
// decode the next nodes so we know where the next node_id starts
189190
pl.light_update();
190191
}
191-
efb.push(iter.get_pos() as _)
192-
.context("Could not write final gamma")?;
192+
efb.push(iter.get_pos() as _);
193193
}
194194
pl.done();
195195

@@ -198,7 +198,7 @@ where
198198
let mut pl = ProgressLogger::default();
199199
pl.display_memory(true);
200200
pl.start("Building the Index over the ones in the high-bits...");
201-
let ef: EF = ef.convert_to().unwrap();
201+
let ef: EF = unsafe { ef.map_high_bits(|bits| SelectAdaptConst::<_, _, 12, 4>::new(bits)) };
202202
pl.done();
203203

204204
let mut pl = ProgressLogger::default();

src/cli/to/bvgraph.rs

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ use crate::prelude::*;
1010
use anyhow::Result;
1111
use clap::{ArgMatches, Args, Command, FromArgMatches};
1212
use dsi_bitstream::prelude::*;
13+
use epserde::deser::DeserializeInner;
1314
use mmap_rs::MmapFlags;
1415
use std::path::PathBuf;
1516
use tempfile::Builder;
@@ -103,14 +104,7 @@ where
103104
DynCodesDecoderFactory<
104105
E,
105106
MmapHelper<u32>,
106-
sux::prelude::EliasFano<
107-
sux::prelude::SelectFixed2<
108-
sux::prelude::CountBitVec<&[usize]>,
109-
&[u64],
110-
8,
111-
>,
112-
sux::prelude::BitFieldVec<usize, &[usize]>,
113-
>,
107+
<EF as DeserializeInner>::DeserType<'_>,
114108
>,
115109
>,
116110
JavaPermutation,

src/graphs/bvgraph/codecs/dec_const.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ use anyhow::Result;
1313
use dsi_bitstream::prelude::*;
1414
use epserde::deser::MemCase;
1515
use sux::traits::IndexedDict;
16+
use sux::traits::IndexedSeq;
1617

1718
/// Temporary constants while const enum generics are not stable
1819
pub mod const_codes {
@@ -187,7 +188,7 @@ impl<
187188
pub struct ConstCodesDecoderFactory<
188189
E: Endianness,
189190
F: BitReaderFactory<E>,
190-
OFF: IndexedDict<Input = usize, Output = usize>,
191+
OFF: IndexedSeq<Input = usize, Output = usize>,
191192
const OUTDEGREES: usize = { const_codes::GAMMA },
192193
const REFERENCES: usize = { const_codes::UNARY },
193194
const BLOCKS: usize = { const_codes::GAMMA },
@@ -207,7 +208,7 @@ pub struct ConstCodesDecoderFactory<
207208
impl<
208209
E: Endianness,
209210
F: BitReaderFactory<E>,
210-
OFF: IndexedDict<Input = usize, Output = usize>,
211+
OFF: IndexedSeq<Input = usize, Output = usize>,
211212
const OUTDEGREES: usize,
212213
const REFERENCES: usize,
213214
const BLOCKS: usize,
@@ -244,7 +245,7 @@ impl<
244245
impl<
245246
E: Endianness,
246247
F: BitReaderFactory<E>,
247-
OFF: IndexedDict<Input = usize, Output = usize>,
248+
OFF: IndexedSeq<Input = usize, Output = usize>,
248249
const OUTDEGREES: usize,
249250
const REFERENCES: usize,
250251
const BLOCKS: usize,

src/graphs/bvgraph/codecs/dec_dyn.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ use super::super::*;
1111
use anyhow::bail;
1212
use dsi_bitstream::prelude::*;
1313
use epserde::deser::MemCase;
14-
use sux::traits::IndexedDict;
14+
use sux::traits::{IndexedDict, IndexedSeq};
1515

1616
#[derive(Debug, Clone)]
1717
pub struct DynCodesDecoder<E: Endianness, CR: CodeRead<E>> {
@@ -136,7 +136,7 @@ impl<E: Endianness, CR: CodeRead<E>> Decode for DynCodesDecoder<E, CR> {
136136
pub struct DynCodesDecoderFactory<
137137
E: Endianness,
138138
F: BitReaderFactory<E>,
139-
OFF: IndexedDict<Input = usize, Output = usize>,
139+
OFF: IndexedSeq<Input = usize, Output = usize>,
140140
> {
141141
/// The owned data we will read as a bitstream.
142142
factory: F,
@@ -159,7 +159,7 @@ pub struct DynCodesDecoderFactory<
159159
_marker: core::marker::PhantomData<E>,
160160
}
161161

162-
impl<E: Endianness, F: BitReaderFactory<E>, OFF: IndexedDict<Input = usize, Output = usize>>
162+
impl<E: Endianness, F: BitReaderFactory<E>, OFF: IndexedSeq<Input = usize, Output = usize>>
163163
DynCodesDecoderFactory<E, F, OFF>
164164
where
165165
for<'a> <F as BitReaderFactory<E>>::BitReader<'a>: CodeRead<E>,
@@ -235,7 +235,7 @@ where
235235
}
236236
}
237237

238-
impl<E: Endianness, F: BitReaderFactory<E>, OFF: IndexedDict<Input = usize, Output = usize>>
238+
impl<E: Endianness, F: BitReaderFactory<E>, OFF: IndexedSeq<Input = usize, Output = usize>>
239239
RandomAccessDecoderFactory for DynCodesDecoderFactory<E, F, OFF>
240240
where
241241
for<'a> <F as BitReaderFactory<E>>::BitReader<'a>: CodeRead<E> + BitSeek,

src/graphs/bvgraph/codecs/factories.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ use std::{
3636
marker::PhantomData,
3737
path::Path,
3838
};
39-
use sux::traits::IndexedDict;
39+
use sux::traits::{IndexedDict, IndexedSeq, Types};
4040

4141
use crate::utils::MmapHelper;
4242

@@ -243,10 +243,12 @@ pub struct EmptyDict<I, O> {
243243
_marker: core::marker::PhantomData<(I, O)>,
244244
}
245245

246-
impl<I, O> IndexedDict for EmptyDict<I, O> {
246+
impl<I, O> Types for EmptyDict<I, O> {
247247
type Input = usize;
248248
type Output = usize;
249+
}
249250

251+
impl<I, O> IndexedSeq for EmptyDict<I, O> {
250252
fn get(&self, _key: Self::Input) -> Self::Output {
251253
panic!();
252254
}

src/graphs/bvgraph/load.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ use std::{
1515
io::BufReader,
1616
path::{Path, PathBuf},
1717
};
18-
use sux::traits::IndexedDict;
18+
use sux::traits::IndexedSeq;
1919

2020
/// Sequential or random access.
2121
#[doc(hidden)]
@@ -87,7 +87,7 @@ pub trait LoadMode: 'static {
8787
flags: codecs::MemoryFlags,
8888
) -> Result<Self::Factory<E>>;
8989

90-
type Offsets: IndexedDict<Input = usize, Output = usize>;
90+
type Offsets: IndexedSeq<Input = usize, Output = usize>;
9191

9292
fn load_offsets<P: AsRef<Path>>(
9393
offsets: P,

src/graphs/bvgraph/mod.rs

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,12 +38,17 @@ pub use load::*;
3838

3939
/// The default version of EliasFano we use for the CLI.
4040
pub type EF = sux::dict::EliasFano<
41-
sux::rank_sel::SelectFixed2<sux::bits::CountBitVec, Vec<u64>, 8>,
42-
sux::bits::BitFieldVec,
41+
sux::rank_sel::SelectAdaptConst<sux::bits::BitVec<Box<[usize]>>, Box<[usize]>, 12, 4>,
42+
sux::bits::BitFieldVec<usize, Box<[usize]>>,
4343
>;
4444

4545
/// The default version of EliasFano we use for the cumulative function of degrees.
4646
pub type DCF = sux::dict::EliasFano<
47-
sux::rank_sel::SelectZeroFixed2<sux::bits::CountBitVec, Vec<u64>, 8>,
48-
sux::bits::BitFieldVec,
47+
sux::rank_sel::SelectZeroAdaptConst<
48+
sux::rank_sel::SelectAdaptConst<sux::bits::BitVec<Box<[usize]>>, Box<[usize]>, 12, 4>,
49+
Box<[usize]>,
50+
12,
51+
4,
52+
>,
53+
sux::bits::BitFieldVec<usize, Box<[usize]>>,
4954
>;

0 commit comments

Comments
 (0)