Skip to content

convert ena to no-std #48

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -10,9 +10,10 @@ readme = "README.md"
keywords = ["unification", "union-find"]

[features]
std = [ ]
bench = [ ]
persistent = [ "dogged" ]
persistent = [ "std", "dogged" ]

[dependencies]
dogged = { version = "0.2.0", optional = true }
log = "0.4"
log = { version = "0.4", optional = true }
301 changes: 0 additions & 301 deletions src/bitvec.rs

This file was deleted.

15 changes: 13 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
@@ -10,15 +10,26 @@

//! An implementation of union-find. See the `unify` module for more
//! details.

#![cfg_attr(feature = "bench", feature(test))]
#![cfg_attr(not(feature = "std"), no_std)]

#[cfg(feature = "std")]
extern crate core;
extern crate alloc;

#[macro_use]
#[cfg(feature = "log")]
extern crate log;

#[cfg(feature = "persistent")]
extern crate dogged;

macro_rules! debug {
($($tt:tt)*) => {
#[cfg(feature = "log")]
log::debug!($($tt)*);
};
}

pub mod snapshot_vec;
pub mod undo_log;
pub mod unify;
9 changes: 5 additions & 4 deletions src/snapshot_vec.rs
Original file line number Diff line number Diff line change
@@ -21,10 +21,11 @@

use self::UndoLog::*;

use std::fmt;
use std::marker::PhantomData;
use std::mem;
use std::ops;
use core::fmt;
use core::marker::PhantomData;
use core::mem;
use core::ops;
use alloc::vec::Vec;

use undo_log::{Rollback, Snapshots, UndoLogs, VecLog};

5 changes: 4 additions & 1 deletion src/undo_log.rs
Original file line number Diff line number Diff line change
@@ -8,6 +8,9 @@
//! Since the `*Storage` variants do not have an undo log `with_log` must be called with the
//! unified log before any mutating actions.

use core::ops;
use alloc::vec::Vec;

/// A trait which allows undo actions (`T`) to be pushed which can be used to rollback actio at a
/// later time if needed.
///
@@ -220,7 +223,7 @@ impl<T> VecLog<T> {
}
}

impl<T> std::ops::Index<usize> for VecLog<T> {
impl<T> ops::Index<usize> for VecLog<T> {
type Output = T;
fn index(&self, key: usize) -> &T {
&self.log[key]
5 changes: 3 additions & 2 deletions src/unify/backing_vec.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
#[cfg(feature = "persistent")]
use dogged::DVec;
use snapshot_vec as sv;
use std::marker::PhantomData;
use std::ops::{self, Range};
use core::marker::PhantomData;
use core::ops::{self, Range};
use alloc::vec::Vec;

use undo_log::{Rollback, Snapshots, UndoLogs, VecLog};

7 changes: 4 additions & 3 deletions src/unify/mod.rs
Original file line number Diff line number Diff line change
@@ -31,9 +31,10 @@
//! The best way to see how it is used is to read the `tests.rs` file;
//! search for e.g. `UnitKey`.
use std::fmt::Debug;
use std::marker;
use std::ops::Range;
use core::fmt::Debug;
use core::marker;
use core::ops::Range;
use alloc::vec::Vec;

use snapshot_vec::{self as sv, UndoLog};
use undo_log::{UndoLogs, VecLog};
6 changes: 5 additions & 1 deletion src/unify/tests.rs
Original file line number Diff line number Diff line change
@@ -14,9 +14,12 @@

#[cfg(feature = "bench")]
extern crate test;

#[cfg(feature = "bench")]
use self::test::Bencher;
use std::cmp;
use core::cmp;
use alloc::vec::Vec;
use alloc::vec;
#[cfg(feature = "persistent")]
use unify::Persistent;
use unify::{EqUnifyValue, InPlace, InPlaceUnificationTable, NoError, UnifyKey, UnifyValue};
@@ -385,6 +388,7 @@ impl UnifyKey for OrderedKey {
b: OrderedKey,
b_rank: &OrderedRank,
) -> Option<(OrderedKey, OrderedKey)> {
#[cfg(feature = "std")]
println!("{:?} vs {:?}", a_rank, b_rank);
if a_rank > b_rank {
Some((a, b))
9 changes: 8 additions & 1 deletion tests/external_undo_log.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,14 @@
#[macro_use]
#[cfg(feature = "log")]
extern crate log;
extern crate ena;

macro_rules! debug {
($($tt:tt)*) => {
#[cfg(feature = "log")]
log::debug!($($tt)*);
};
}

use ena::{
snapshot_vec as sv,
undo_log::{Rollback, Snapshots, UndoLogs},