Skip to content

Use usize indexes #40

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 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
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
10 changes: 5 additions & 5 deletions src/unify/backing_vec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ pub trait UnificationStoreBase: ops::Index<usize, Output = VarValue<Key<Self>>>
}

pub trait UnificationStoreMut: UnificationStoreBase {
fn reset_unifications(&mut self, value: impl FnMut(u32) -> VarValue<Self::Key>);
fn reset_unifications(&mut self, value: impl FnMut(usize) -> VarValue<Self::Key>);

fn push(&mut self, value: VarValue<Self::Key>);

Expand Down Expand Up @@ -90,8 +90,8 @@ where
L: UndoLogs<sv::UndoLog<Delegate<K>>>,
{
#[inline]
fn reset_unifications(&mut self, mut value: impl FnMut(u32) -> VarValue<Self::Key>) {
self.values.set_all(|i| value(i as u32));
fn reset_unifications(&mut self, mut value: impl FnMut(usize) -> VarValue<Self::Key>) {
self.values.set_all(|i| value(i));
}

#[inline]
Expand Down Expand Up @@ -199,12 +199,12 @@ impl<K: UnifyKey> UnificationStoreBase for Persistent<K> {
#[cfg(feature = "persistent")]
impl<K: UnifyKey> UnificationStoreMut for Persistent<K> {
#[inline]
fn reset_unifications(&mut self, mut value: impl FnMut(u32) -> VarValue<Self::Key>) {
fn reset_unifications(&mut self, mut value: impl FnMut(usize) -> VarValue<Self::Key>) {
// Without extending dogged, there isn't obviously a more
// efficient way to do this. But it's pretty dumb. Maybe
// dogged needs a `map`.
for i in 0..self.values.len() {
self.values[i] = value(i as u32);
self.values[i] = value(i);
}
}

Expand Down
10 changes: 5 additions & 5 deletions src/unify/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,9 @@ mod tests;
pub trait UnifyKey: Copy + Clone + Debug + PartialEq {
type Value: UnifyValue;

fn index(&self) -> u32;
fn index(&self) -> usize;

fn from_index(u: u32) -> Self;
fn from_index(u: usize) -> Self;

fn tag() -> &'static str;

Expand Down Expand Up @@ -302,7 +302,7 @@ impl<S: UnificationStore> UnificationTable<S> {
/// Returns the keys of all variables created since the `snapshot`.
pub fn vars_since_snapshot(&self, snapshot: &Snapshot<S>) -> Range<S::Key> {
let range = self.values.values_since_snapshot(&snapshot.snapshot);
S::Key::from_index(range.start as u32)..S::Key::from_index(range.end as u32)
S::Key::from_index(range.start)..S::Key::from_index(range.end)
}
}

Expand All @@ -318,7 +318,7 @@ impl<S: UnificationStoreMut> UnificationTable<S> {
/// Creates a fresh key with the given value.
pub fn new_key(&mut self, value: S::Value) -> S::Key {
let len = self.values.len();
let key: S::Key = UnifyKey::from_index(len as u32);
let key: S::Key = UnifyKey::from_index(len);
self.values.push(VarValue::new_var(key, value));
debug!("{}: created new key: {:?}", S::tag(), key);
key
Expand All @@ -335,7 +335,7 @@ impl<S: UnificationStoreMut> UnificationTable<S> {
/// the closure.
pub fn reset_unifications(&mut self, mut value: impl FnMut(S::Key) -> S::Value) {
self.values.reset_unifications(|i| {
let key = UnifyKey::from_index(i as u32);
let key = UnifyKey::from_index(i);
let value = value(key);
VarValue::new_var(key, value)
});
Expand Down
20 changes: 10 additions & 10 deletions src/unify/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,14 @@ use unify::{EqUnifyValue, InPlace, InPlaceUnificationTable, NoError, UnifyKey, U
use unify::{UnificationStore, UnificationTable};

#[derive(Copy, Clone, Debug, Hash, PartialEq, Eq)]
struct UnitKey(u32);
struct UnitKey(usize);

impl UnifyKey for UnitKey {
type Value = ();
fn index(&self) -> u32 {
fn index(&self) -> usize {
self.0
}
fn from_index(u: u32) -> UnitKey {
fn from_index(u: usize) -> UnitKey {
UnitKey(u)
}
fn tag() -> &'static str {
Expand Down Expand Up @@ -242,14 +242,14 @@ fn even_odd() {
}

#[derive(Copy, Clone, Debug, Hash, PartialEq, Eq)]
struct IntKey(u32);
struct IntKey(usize);

impl UnifyKey for IntKey {
type Value = Option<i32>;
fn index(&self) -> u32 {
fn index(&self) -> usize {
self.0
}
fn from_index(u: u32) -> IntKey {
fn from_index(u: usize) -> IntKey {
IntKey(u)
}
fn tag() -> &'static str {
Expand Down Expand Up @@ -363,17 +363,17 @@ fn unify_root_value_2() {
}

#[derive(Copy, Clone, Debug, Hash, PartialEq, Eq)]
struct OrderedKey(u32);
struct OrderedKey(usize);

#[derive(Copy, Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)]
struct OrderedRank(u32);
struct OrderedRank(usize);

impl UnifyKey for OrderedKey {
type Value = OrderedRank;
fn index(&self) -> u32 {
fn index(&self) -> usize {
self.0
}
fn from_index(u: u32) -> OrderedKey {
fn from_index(u: usize) -> OrderedKey {
OrderedKey(u)
}
fn tag() -> &'static str {
Expand Down
6 changes: 3 additions & 3 deletions tests/external_undo_log.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@ use ena::{
};

#[derive(Copy, Clone, Debug, Hash, PartialEq, Eq)]
struct IntKey(u32);
struct IntKey(usize);

impl UnifyKey for IntKey {
type Value = Option<IntKey>;
fn index(&self) -> u32 {
fn index(&self) -> usize {
self.0
}
fn from_index(u: u32) -> IntKey {
fn from_index(u: usize) -> IntKey {
IntKey(u)
}
fn tag() -> &'static str {
Expand Down