-
Notifications
You must be signed in to change notification settings - Fork 1k
Make VID element internal to the Entity #5857
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
Changes from all commits
eb9d33c
a4f9376
203d397
133f79a
c167fbb
7d7ef14
c8a9f9e
5370101
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -308,6 +308,45 @@ impl<V> Object<V> { | |
} | ||
} | ||
|
||
impl<V: PartialEq> Object<V> { | ||
fn len_ignore_atom(&self, atom: &Atom) -> usize { | ||
// Because of tombstones and the ignored atom, we can't just return `self.entries.len()`. | ||
self.entries | ||
.iter() | ||
.filter(|entry| entry.key != TOMBSTONE_KEY && entry.key != *atom) | ||
.count() | ||
} | ||
|
||
/// Check for equality while ignoring one particular element | ||
pub fn eq_ignore_key(&self, other: &Self, ignore_key: &str) -> bool { | ||
let ignore = self.pool.lookup(ignore_key); | ||
let len1 = if let Some(to_ignore) = ignore { | ||
self.len_ignore_atom(&to_ignore) | ||
} else { | ||
self.len() | ||
}; | ||
let len2 = if let Some(to_ignore) = other.pool.lookup(ignore_key) { | ||
other.len_ignore_atom(&to_ignore) | ||
} else { | ||
other.len() | ||
}; | ||
if len1 != len2 { | ||
return false; | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is very minor, but since you need to traverse the list of key/value pairs to determine the length, there's not much value in trying to short-circuit the comparison based on length since you already need to load everything into cache. I would just leave the length-based optimization out and go straight to comparing based on values. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. On a second thought the size comparison avoids false positive when elements in |
||
|
||
if self.same_pool(other) { | ||
self.entries | ||
.iter() | ||
.filter(|e| e.key != TOMBSTONE_KEY && ignore.map_or(true, |ig| e.key != ig)) | ||
.all(|Entry { key, value }| other.get_by_atom(key).map_or(false, |o| o == value)) | ||
} else { | ||
self.iter() | ||
.filter(|(key, _)| *key != ignore_key) | ||
.all(|(key, value)| other.get(key).map_or(false, |o| o == value)) | ||
} | ||
} | ||
} | ||
|
||
impl<V: NullValue> Object<V> { | ||
/// Remove `key` from the object and return the value that was | ||
/// associated with the `key`. The entry is actually not removed for | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this also needs to be changed so that
entity.iter()
andentity.into_iter()
do not show thevid
, something likeUh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You should also add unit tests at teh end of the file that show that the various methods behave well when there is a
vid
(e.g., that iteration andsorted
do not include thevid
)There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Best I could do is use
retain()
. Can we postpone the UT for later moment?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I just noticed that the original already had that really surprising and unnecessary clone in it. After playing around a little and consulting this, I think this would work and gets rid of the clone, too:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Beautiful! That removes two copies - the original clone and my retain! BTW added the test.