Skip to content

Commit

Permalink
fixed clippy and fmt
Browse files Browse the repository at this point in the history
  • Loading branch information
Tommaso Fontana committed Feb 8, 2024
1 parent 2c32091 commit 6ce6edc
Show file tree
Hide file tree
Showing 6 changed files with 109 additions and 70 deletions.
1 change: 1 addition & 0 deletions src/algo/transpose.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ where
Ok(sorted)
}

#[allow(clippy::type_complexity)]
pub fn transpose(
graph: impl SequentialGraph,
batch_size: usize,
Expand Down
108 changes: 55 additions & 53 deletions src/cli/bench_bvgraph.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,12 +77,7 @@ pub fn main(submatches: &ArgMatches) -> Result<()> {
}
}

fn bench_random<E: Endianness>(
graph: impl RandomAccessGraph,
samples: usize,
repeats: usize,
first: bool,
) {
fn bench_random(graph: impl RandomAccessGraph, samples: usize, repeats: usize, first: bool) {
// Random-access speed test
for _ in 0..repeats {
let mut rng = SmallRng::seed_from_u64(0);
Expand Down Expand Up @@ -118,7 +113,7 @@ fn bench_random<E: Endianness>(
}
}

fn bench_seq<E: Endianness>(graph: impl SequentialGraph, repeats: usize) {
fn bench_seq(graph: impl SequentialGraph, repeats: usize) {
for _ in 0..repeats {
let mut c: u64 = 0;

Expand Down Expand Up @@ -169,7 +164,7 @@ where
let mut c: u64 = 0;
let start = std::time::Instant::now();
for _ in 0..seq_graph.num_nodes() {
black_box(c += deg_reader.next_degree()? as u64);
c += black_box(deg_reader.next_degree()? as u64);
}
println!(
"Degrees Only:{:>20} ns/arc",
Expand All @@ -178,52 +173,59 @@ where

assert_eq!(c, seq_graph.num_arcs_hint().unwrap());
}
} else if let Some(samples) = args.random {
if std::any::TypeId::of::<D>() == std::any::TypeId::of::<Dynamic>() {
bench_random::<E>(
BVGraph::with_basename(&args.basename)
.endianness::<E>()
.mode::<Mmap>()
.flags(MemoryFlags::TRANSPARENT_HUGE_PAGES | MemoryFlags::RANDOM_ACCESS)
.load()?,
samples,
args.repeats,
args.first,
);
} else {
bench_random::<E>(
BVGraph::with_basename(&args.basename)
.endianness::<E>()
.dispatch::<Static>()
.mode::<Mmap>()
.flags(MemoryFlags::TRANSPARENT_HUGE_PAGES | MemoryFlags::RANDOM_ACCESS)
.load()?,
samples,
args.repeats,
args.first,
);
}
} else {
if std::any::TypeId::of::<D>() == std::any::TypeId::of::<Dynamic>() {
bench_seq::<E>(
BVGraphSeq::with_basename(&args.basename)
.endianness::<E>()
.dispatch::<Dynamic>()
.mode::<Mmap>()
.flags(MemoryFlags::TRANSPARENT_HUGE_PAGES | MemoryFlags::SEQUENTIAL)
.load()?,
args.repeats,
);
} else {
bench_seq::<E>(
BVGraphSeq::with_basename(&args.basename)
.endianness::<E>()
.dispatch::<Static>()
.mode::<Mmap>()
.flags(MemoryFlags::TRANSPARENT_HUGE_PAGES | MemoryFlags::SEQUENTIAL)
.load()?,
args.repeats,
);
match (
args.random,
std::any::TypeId::of::<D>() == std::any::TypeId::of::<Dynamic>(),
) {
(Some(samples), true) => {
bench_random(
BVGraph::with_basename(&args.basename)
.endianness::<E>()
.dispatch::<Dynamic>()
.mode::<Mmap>()
.flags(MemoryFlags::TRANSPARENT_HUGE_PAGES | MemoryFlags::RANDOM_ACCESS)
.load()?,
samples,
args.repeats,
args.first,
);
}
(Some(samples), false) => {
bench_random(
BVGraph::with_basename(&args.basename)
.endianness::<E>()
.dispatch::<Static>()
.mode::<Mmap>()
.flags(MemoryFlags::TRANSPARENT_HUGE_PAGES | MemoryFlags::RANDOM_ACCESS)
.load()?,
samples,
args.repeats,
args.first,
);
}
(None, true) => {
bench_seq(
BVGraphSeq::with_basename(&args.basename)
.endianness::<E>()
.dispatch::<Dynamic>()
.mode::<Mmap>()
.flags(MemoryFlags::TRANSPARENT_HUGE_PAGES | MemoryFlags::SEQUENTIAL)
.load()?,
args.repeats,
);
}
(None, false) => {
bench_seq(
BVGraphSeq::with_basename(&args.basename)
.endianness::<E>()
.dispatch::<Static>()
.mode::<Mmap>()
.flags(MemoryFlags::TRANSPARENT_HUGE_PAGES | MemoryFlags::SEQUENTIAL)
.load()?,
args.repeats,
);
}
}
}
Ok(())
Expand Down
10 changes: 10 additions & 0 deletions src/graphs/bvgraph/codecs/enc_dyn.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,23 @@ use std::convert::Infallible;

pub struct DynCodesEncoder<E: Endianness, CW: CodeWrite<E>> {
code_writer: CW,
#[allow(clippy::type_complexity)]
write_outdegree: fn(&mut CW, u64) -> Result<usize, <CW as BitWrite<E>>::Error>,
#[allow(clippy::type_complexity)]
write_reference_offset: fn(&mut CW, u64) -> Result<usize, <CW as BitWrite<E>>::Error>,
#[allow(clippy::type_complexity)]
write_block_count: fn(&mut CW, u64) -> Result<usize, <CW as BitWrite<E>>::Error>,
#[allow(clippy::type_complexity)]
write_blocks: fn(&mut CW, u64) -> Result<usize, <CW as BitWrite<E>>::Error>,
#[allow(clippy::type_complexity)]
write_interval_count: fn(&mut CW, u64) -> Result<usize, <CW as BitWrite<E>>::Error>,
#[allow(clippy::type_complexity)]
write_interval_start: fn(&mut CW, u64) -> Result<usize, <CW as BitWrite<E>>::Error>,
#[allow(clippy::type_complexity)]
write_interval_len: fn(&mut CW, u64) -> Result<usize, <CW as BitWrite<E>>::Error>,
#[allow(clippy::type_complexity)]
write_first_residual: fn(&mut CW, u64) -> Result<usize, <CW as BitWrite<E>>::Error>,
#[allow(clippy::type_complexity)]
write_residual: fn(&mut CW, u64) -> Result<usize, <CW as BitWrite<E>>::Error>,
_marker: core::marker::PhantomData<E>,
}
Expand Down Expand Up @@ -60,6 +69,7 @@ fn write_zeta7<E: Endianness, CW: CodeWrite<E>>(
}

impl<E: Endianness, CW: CodeWrite<E>> DynCodesEncoder<E, CW> {
#[allow(clippy::type_complexity)]
fn select_code(code: Code) -> fn(&mut CW, u64) -> Result<usize, <CW as BitWrite<E>>::Error> {
match code {
Code::Unary => CW::write_unary,
Expand Down
51 changes: 38 additions & 13 deletions src/graphs/bvgraph/load.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,14 +84,17 @@ impl Dispatch for Dynamic {}
pub trait LoadMode: 'static {
type Factory<E: Endianness>: BitReaderFactory<E>;

fn new_factory<E: Endianness>(
graph: &PathBuf,
fn new_factory<E: Endianness, P: AsRef<Path>>(
graph: P,
flags: codecs::MemoryFlags,
) -> Result<Self::Factory<E>>;

type Offsets: IndexedDict<Input = usize, Output = usize>;

fn load_offsets(offsets: &PathBuf, flags: MemoryFlags) -> Result<MemCase<Self::Offsets>>;
fn load_offsets<P: AsRef<Path>>(
offsets: P,
flags: MemoryFlags,
) -> Result<MemCase<Self::Offsets>>;
}

/// The graph is read from a file; offsets are fully deserialized in memory.
Expand All @@ -105,14 +108,17 @@ impl LoadMode for File {
type Factory<E: Endianness> = FileFactory<E>;
type Offsets = EF;

fn new_factory<E: Endianness>(
graph: &PathBuf,
fn new_factory<E: Endianness, P: AsRef<Path>>(
graph: P,
_flags: MemoryFlags,
) -> Result<Self::Factory<E>> {
FileFactory::<E>::new(graph)
}

fn load_offsets(offsets: &PathBuf, _flags: MemoryFlags) -> Result<MemCase<Self::Offsets>> {
fn load_offsets<P: AsRef<Path>>(
offsets: P,
_flags: MemoryFlags,
) -> Result<MemCase<Self::Offsets>> {
Ok(EF::load_full(offsets)?.into())
}
}
Expand All @@ -127,11 +133,17 @@ impl LoadMode for Mmap {
type Factory<E: Endianness> = MmapBackend<u32>;
type Offsets = DeserType<'static, EF>;

fn new_factory<E: Endianness>(graph: &PathBuf, flags: MemoryFlags) -> Result<Self::Factory<E>> {
fn new_factory<E: Endianness, P: AsRef<Path>>(
graph: P,
flags: MemoryFlags,
) -> Result<Self::Factory<E>> {
MmapBackend::load(graph, flags.into())
}

fn load_offsets(offsets: &PathBuf, flags: MemoryFlags) -> Result<MemCase<Self::Offsets>> {
fn load_offsets<P: AsRef<Path>>(
offsets: P,
flags: MemoryFlags,
) -> Result<MemCase<Self::Offsets>> {
EF::mmap(offsets, flags.into())
}
}
Expand All @@ -144,14 +156,17 @@ impl LoadMode for LoadMem {
type Factory<E: Endianness> = MemoryFactory<E, Box<[u32]>>;
type Offsets = DeserType<'static, EF>;

fn new_factory<E: Endianness>(
graph: &PathBuf,
fn new_factory<E: Endianness, P: AsRef<Path>>(
graph: P,
_flags: MemoryFlags,
) -> Result<Self::Factory<E>> {
MemoryFactory::<E, _>::new_mem(graph)
}

fn load_offsets(offsets: &PathBuf, _flags: MemoryFlags) -> Result<MemCase<Self::Offsets>> {
fn load_offsets<P: AsRef<Path>>(
offsets: P,
_flags: MemoryFlags,
) -> Result<MemCase<Self::Offsets>> {
EF::load_mem(offsets)
}
}
Expand All @@ -166,11 +181,17 @@ impl LoadMode for LoadMmap {
type Factory<E: Endianness> = MemoryFactory<E, MmapBackend<u32>>;
type Offsets = DeserType<'static, EF>;

fn new_factory<E: Endianness>(graph: &PathBuf, flags: MemoryFlags) -> Result<Self::Factory<E>> {
fn new_factory<E: Endianness, P: AsRef<Path>>(
graph: P,
flags: MemoryFlags,
) -> Result<Self::Factory<E>> {
MemoryFactory::<E, _>::new_mmap(graph, flags)
}

fn load_offsets(offsets: &PathBuf, flags: MemoryFlags) -> Result<MemCase<Self::Offsets>> {
fn load_offsets<P: AsRef<Path>>(
offsets: P,
flags: MemoryFlags,
) -> Result<MemCase<Self::Offsets>> {
EF::load_mmap(offsets, flags.into())
}
}
Expand Down Expand Up @@ -326,6 +347,7 @@ impl<E: Endianness, D: Dispatch, GLM: LoadMode> LoadConfig<E, Random, D, GLM, Lo

impl<E: Endianness, GLM: LoadMode, OLM: LoadMode> LoadConfig<E, Random, Dynamic, GLM, OLM> {
/// Load a random-access graph with dynamic dispatch.
#[allow(clippy::type_complexity)]
pub fn load(
mut self,
) -> anyhow::Result<BVGraph<DynCodesDecoderFactory<E, GLM::Factory<E>, OLM::Offsets>>>
Expand All @@ -352,6 +374,7 @@ impl<E: Endianness, GLM: LoadMode, OLM: LoadMode> LoadConfig<E, Random, Dynamic,

impl<E: Endianness, GLM: LoadMode, OLM: LoadMode> LoadConfig<E, Sequential, Dynamic, GLM, OLM> {
/// Load a sequential graph with dynamic dispatch.
#[allow(clippy::type_complexity)]
pub fn load(
mut self,
) -> anyhow::Result<
Expand Down Expand Up @@ -389,6 +412,7 @@ impl<
LoadConfig<E, Random, Static<OUTDEGREES, REFERENCES, BLOCKS, INTERVALS, RESIDUALS, K>, GLM, OLM>
{
/// Load a random-access graph with static dispatch.
#[allow(clippy::type_complexity)]
pub fn load(
mut self,
) -> anyhow::Result<
Expand Down Expand Up @@ -447,6 +471,7 @@ impl<
>
{
/// Load a sequential graph with static dispatch.
#[allow(clippy::type_complexity)]
pub fn load(
mut self,
) -> anyhow::Result<
Expand Down
8 changes: 4 additions & 4 deletions src/traits/graph.rs
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ impl<I: Iterator<Item = usize>> Iterator for UnitSuccessors<I> {
}
}

impl<'a, G: SequentialGraph> SequentialLabeling for UnitLabelGraph<G> {
impl<G: SequentialGraph> SequentialLabeling for UnitLabelGraph<G> {
type Label = (usize, ());

type Iterator<'node> = UnitIterator<G::Iterator<'node>>
Expand All @@ -171,7 +171,7 @@ impl<'a, G: SequentialGraph> SequentialLabeling for UnitLabelGraph<G> {
}
}

impl<'a, G: SequentialGraph> LabeledSequentialGraph<()> for UnitLabelGraph<G> {}
impl<G: SequentialGraph> LabeledSequentialGraph<()> for UnitLabelGraph<G> {}

/// A labeled random-access graph.
///
Expand Down Expand Up @@ -220,7 +220,7 @@ pub trait LabeledRandomAccessGraph<L>: RandomAccessLabeling<Label = (usize, L)>
}
}

impl<'a, G: RandomAccessGraph> RandomAccessLabeling for UnitLabelGraph<G> {
impl<G: RandomAccessGraph> RandomAccessLabeling for UnitLabelGraph<G> {
type Labels<'succ> =
UnitSuccessors<<<G as RandomAccessLabeling>::Labels<'succ> as IntoIterator>::IntoIter>
where Self: 'succ;
Expand All @@ -238,4 +238,4 @@ impl<'a, G: RandomAccessGraph> RandomAccessLabeling for UnitLabelGraph<G> {
}
}

impl<'a, G: RandomAccessGraph> LabeledRandomAccessGraph<()> for UnitLabelGraph<G> {}
impl<G: RandomAccessGraph> LabeledRandomAccessGraph<()> for UnitLabelGraph<G> {}
1 change: 1 addition & 0 deletions src/utils/mmap_backend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@ impl<W> MmapBackend<W, MmapMut> {
.read(true)
.write(true)
.create(true)
.truncate(true)
.open(path.as_ref())
.with_context(|| {
format!(
Expand Down

0 comments on commit 6ce6edc

Please sign in to comment.