mirror of
https://github.com/martinvonz/jj.git
synced 2024-10-24 23:47:22 +00:00
id_prefix: add IdIndex::has_key()
For the support for shorter prefixes within a revset, we'll want to be able to check if an id is in the index.
This commit is contained in:
parent
481b8c5d0e
commit
2e12aad1f7
1 changed files with 16 additions and 0 deletions
|
@ -108,6 +108,10 @@ where
|
||||||
.map(|(k, v)| (k, v))
|
.map(|(k, v)| (k, v))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn has_key(&self, key: &K) -> bool {
|
||||||
|
self.0.binary_search_by(|(k, _)| k.cmp(key)).is_ok()
|
||||||
|
}
|
||||||
|
|
||||||
/// This function returns the shortest length of a prefix of `key` that
|
/// This function returns the shortest length of a prefix of `key` that
|
||||||
/// disambiguates it from every other key in the index.
|
/// disambiguates it from every other key in the index.
|
||||||
///
|
///
|
||||||
|
@ -192,6 +196,18 @@ mod tests {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_has_key() {
|
||||||
|
// No crash if empty
|
||||||
|
let id_index = IdIndex::from_vec(vec![] as Vec<(ChangeId, ())>);
|
||||||
|
assert!(!id_index.has_key(&ChangeId::from_hex("00")));
|
||||||
|
|
||||||
|
let id_index = IdIndex::from_vec(vec![(ChangeId::from_hex("ab"), ())]);
|
||||||
|
assert!(!id_index.has_key(&ChangeId::from_hex("aa")));
|
||||||
|
assert!(id_index.has_key(&ChangeId::from_hex("ab")));
|
||||||
|
assert!(!id_index.has_key(&ChangeId::from_hex("ac")));
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_id_index_shortest_unique_prefix_len() {
|
fn test_id_index_shortest_unique_prefix_len() {
|
||||||
// No crash if empty
|
// No crash if empty
|
||||||
|
|
Loading…
Reference in a new issue