Skip to content
Merged
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
9 changes: 5 additions & 4 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,4 @@ quote = "1.0"
syn = "2.0"
trybuild = "1.0.103"
uuid = "1.12.0"
indexmap = "2.11.4"
2 changes: 2 additions & 0 deletions daft/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ workspace = true

[dependencies]
daft-derive = { workspace = true, optional = true }
indexmap = { workspace = true, optional = true }
newtype-uuid = { workspace = true, optional = true }
oxnet = { workspace = true, optional = true }
paste.workspace = true
Expand All @@ -28,6 +29,7 @@ derive = ["dep:daft-derive"]
newtype-uuid1 = ["dep:newtype-uuid"]
oxnet01 = ["dep:oxnet"]
uuid1 = ["dep:uuid"]
indexmap = ["dep:indexmap", "alloc"]

[package.metadata.docs.rs]
all-features = true
Expand Down
72 changes: 72 additions & 0 deletions daft/src/third_party/indexmap.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
use crate::Diffable;
use core::hash::Hash;
use indexmap::{IndexMap, IndexSet};

map_diff!(IndexMap, Hash);
set_diff!(IndexSet, Hash);

#[cfg(test)]
mod tests {
use super::*;
use crate::Leaf;
use alloc::vec::Vec;

#[test]
fn indexmap_set_diff() {
let a: IndexSet<_> = [0, 1, 2, 3, 4, 5].into_iter().collect();
let b: IndexSet<_> = [3, 4, 5, 6, 7, 8].into_iter().collect();
Comment on lines +16 to +17
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just did a small tweak here to avoid using the fully-qualified name. (Not sure if you used an LLM to write this -- that's okay but unnecessarily using fully-qualified names is something Claude in particular is prone to do, and something to watch out for.)

let changes = a.diff(&b);
let expected = IndexSetDiff {
added: [&6, &7, &8].into_iter().collect(),
removed: [&0, &1, &2].into_iter().collect(),
common: [&3, &4, &5].into_iter().collect(),
};
assert_eq!(expected, changes);
}

#[test]
fn indexmap_map_diff() {
let a: IndexMap<_, _> = [(0, 1), (1, 1), (2, 1)].into_iter().collect();
let b: IndexMap<_, _> = [(0, 2), (2, 1), (3, 1)].into_iter().collect();

let changes = a.diff(&b);
let expected = IndexMapDiff {
common: [
(&0, Leaf { before: &1, after: &2 }),
(&2, Leaf { before: &1, after: &1 }),
]
.into_iter()
.collect(),
added: [(&3, &1)].into_iter().collect(),
removed: [(&1, &1)].into_iter().collect(),
};

assert_eq!(changes, expected);

// Ensure that keys don't need to be Diffable, and values don't need to
// be Eq or Diffable.
#[derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash)]
struct K(i32);

#[derive(Debug)]
#[expect(dead_code)]
struct V(f64);

let floats_a: IndexMap<K, V> =
[(K(0), V(1.0)), (K(1), V(1.0)), (K(2), V(1.0))]
.into_iter()
.collect();
let floats_b: IndexMap<K, V> =
[(K(0), V(2.0)), (K(2), V(1.0)), (K(3), V(1.0))]
.into_iter()
.collect();

let diff = floats_a.diff(&floats_b);
assert_eq!(diff.added.keys().copied().collect::<Vec<_>>(), [&K(3)]);
assert_eq!(diff.removed.keys().copied().collect::<Vec<_>>(), [&K(1)]);
assert_eq!(
diff.common.keys().copied().collect::<Vec<_>>(),
[&K(0), &K(2)]
);
}
}
2 changes: 2 additions & 0 deletions daft/src/third_party/mod.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
//! Implementations for third-party libraries.

#[cfg(feature = "indexmap")]
mod indexmap;
#[cfg(feature = "newtype-uuid1")]
mod newtype_uuid_impls;
#[cfg(feature = "oxnet01")]
Expand Down
Loading