Show More
@@ -70,6 +70,18 b' dependencies = [' | |||||
70 | ] |
|
70 | ] | |
71 |
|
71 | |||
72 | [[package]] |
|
72 | [[package]] | |
|
73 | name = "bitvec" | |||
|
74 | version = "1.0.1" | |||
|
75 | source = "registry+https://github.com/rust-lang/crates.io-index" | |||
|
76 | checksum = "1bc2832c24239b0141d5674bb9174f9d68a8b5b3f2753311927c172ca46f7e9c" | |||
|
77 | dependencies = [ | |||
|
78 | "funty", | |||
|
79 | "radium", | |||
|
80 | "tap", | |||
|
81 | "wyz", | |||
|
82 | ] | |||
|
83 | ||||
|
84 | [[package]] | |||
73 | name = "block-buffer" |
|
85 | name = "block-buffer" | |
74 | version = "0.9.0" |
|
86 | version = "0.9.0" | |
75 | source = "registry+https://github.com/rust-lang/crates.io-index" |
|
87 | source = "registry+https://github.com/rust-lang/crates.io-index" | |
@@ -443,6 +455,12 b' dependencies = [' | |||||
443 | ] |
|
455 | ] | |
444 |
|
456 | |||
445 | [[package]] |
|
457 | [[package]] | |
|
458 | name = "funty" | |||
|
459 | version = "2.0.0" | |||
|
460 | source = "registry+https://github.com/rust-lang/crates.io-index" | |||
|
461 | checksum = "e6d5a32815ae3f33302d95fdcb2ce17862f8c65363dcfd29360480ba1001fc9c" | |||
|
462 | ||||
|
463 | [[package]] | |||
446 | name = "generic-array" |
|
464 | name = "generic-array" | |
447 | version = "0.14.6" |
|
465 | version = "0.14.6" | |
448 | source = "registry+https://github.com/rust-lang/crates.io-index" |
|
466 | source = "registry+https://github.com/rust-lang/crates.io-index" | |
@@ -516,6 +534,7 b' name = "hg-core"' | |||||
516 | version = "0.1.0" |
|
534 | version = "0.1.0" | |
517 | dependencies = [ |
|
535 | dependencies = [ | |
518 | "bitflags", |
|
536 | "bitflags", | |
|
537 | "bitvec", | |||
519 | "byteorder", |
|
538 | "byteorder", | |
520 | "bytes-cast", |
|
539 | "bytes-cast", | |
521 | "clap", |
|
540 | "clap", | |
@@ -915,6 +934,12 b' dependencies = [' | |||||
915 | ] |
|
934 | ] | |
916 |
|
935 | |||
917 | [[package]] |
|
936 | [[package]] | |
|
937 | name = "radium" | |||
|
938 | version = "0.7.0" | |||
|
939 | source = "registry+https://github.com/rust-lang/crates.io-index" | |||
|
940 | checksum = "dc33ff2d4973d518d823d61aa239014831e521c75da58e3df4840d3f47749d09" | |||
|
941 | ||||
|
942 | [[package]] | |||
918 | name = "rand" |
|
943 | name = "rand" | |
919 | version = "0.7.3" |
|
944 | version = "0.7.3" | |
920 | source = "registry+https://github.com/rust-lang/crates.io-index" |
|
945 | source = "registry+https://github.com/rust-lang/crates.io-index" | |
@@ -1226,6 +1251,12 b' dependencies = [' | |||||
1226 | ] |
|
1251 | ] | |
1227 |
|
1252 | |||
1228 | [[package]] |
|
1253 | [[package]] | |
|
1254 | name = "tap" | |||
|
1255 | version = "1.0.1" | |||
|
1256 | source = "registry+https://github.com/rust-lang/crates.io-index" | |||
|
1257 | checksum = "55937e1799185b12863d447f42597ed69d9928686b8d88a1df17376a097d8369" | |||
|
1258 | ||||
|
1259 | [[package]] | |||
1229 | name = "tempfile" |
|
1260 | name = "tempfile" | |
1230 | version = "3.3.0" |
|
1261 | version = "3.3.0" | |
1231 | source = "registry+https://github.com/rust-lang/crates.io-index" |
|
1262 | source = "registry+https://github.com/rust-lang/crates.io-index" | |
@@ -1489,6 +1520,15 b' source = "registry+https://github.com/ru' | |||||
1489 | checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" |
|
1520 | checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" | |
1490 |
|
1521 | |||
1491 | [[package]] |
|
1522 | [[package]] | |
|
1523 | name = "wyz" | |||
|
1524 | version = "0.5.1" | |||
|
1525 | source = "registry+https://github.com/rust-lang/crates.io-index" | |||
|
1526 | checksum = "05f360fc0b24296329c78fda852a1e9ae82de9cf7b27dae4b7f62f118f77b9ed" | |||
|
1527 | dependencies = [ | |||
|
1528 | "tap", | |||
|
1529 | ] | |||
|
1530 | ||||
|
1531 | [[package]] | |||
1492 | name = "yansi" |
|
1532 | name = "yansi" | |
1493 | version = "0.5.1" |
|
1533 | version = "0.5.1" | |
1494 | source = "registry+https://github.com/rust-lang/crates.io-index" |
|
1534 | source = "registry+https://github.com/rust-lang/crates.io-index" |
@@ -39,6 +39,7 b' memmap2 = { version = "0.5.8", features ' | |||||
39 | zstd = "0.12" |
|
39 | zstd = "0.12" | |
40 | format-bytes = "0.3.0" |
|
40 | format-bytes = "0.3.0" | |
41 | once_cell = "1.16.0" |
|
41 | once_cell = "1.16.0" | |
|
42 | bitvec = "1.0.1" | |||
42 |
|
43 | |||
43 | # We don't use the `miniz-oxide` backend to not change rhg benchmarks and until |
|
44 | # We don't use the `miniz-oxide` backend to not change rhg benchmarks and until | |
44 | # we have a clearer view of which backend is the fastest. |
|
45 | # we have a clearer view of which backend is the fastest. |
@@ -12,6 +12,8 b'' | |||||
12 | //! mean those revisions that have no children among the collection. |
|
12 | //! mean those revisions that have no children among the collection. | |
13 | //! - Similarly *relative roots* of a collection of `Revision`, we mean those |
|
13 | //! - Similarly *relative roots* of a collection of `Revision`, we mean those | |
14 | //! whose parents, if any, don't belong to the collection. |
|
14 | //! whose parents, if any, don't belong to the collection. | |
|
15 | use bitvec::slice::BitSlice; | |||
|
16 | ||||
15 | use super::{Graph, GraphError, Revision, NULL_REVISION}; |
|
17 | use super::{Graph, GraphError, Revision, NULL_REVISION}; | |
16 | use crate::{ancestors::AncestorsIterator, BaseRevision}; |
|
18 | use crate::{ancestors::AncestorsIterator, BaseRevision}; | |
17 | use std::collections::{BTreeSet, HashSet}; |
|
19 | use std::collections::{BTreeSet, HashSet}; | |
@@ -81,26 +83,26 b' pub fn retain_heads<S: std::hash::BuildH' | |||||
81 | Ok(()) |
|
83 | Ok(()) | |
82 | } |
|
84 | } | |
83 |
|
85 | |||
84 |
/// Optimized version of `retain_heads` that expects an zeroed |
|
86 | /// Optimized version of `retain_heads` that expects an zeroed bitvec of the | |
85 | /// of the graph, to act as a faster but less space-efficient `HashSet`. |
|
87 | /// size of the graph, to act as a faster but less space-efficient `HashSet`. | |
86 | /// |
|
88 | /// | |
87 | /// # Panics |
|
89 | /// # Panics | |
88 | /// |
|
90 | /// | |
89 | /// Can panic if `not_heads` is shorten than the length of graph. |
|
91 | /// Can panic if `not_heads` is shorten than the length of graph. | |
90 | pub fn retain_heads_fast( |
|
92 | pub fn retain_heads_fast( | |
91 | graph: &impl Graph, |
|
93 | graph: &impl Graph, | |
92 |
not_heads: &mut |
|
94 | not_heads: &mut BitSlice, | |
93 | filtered_revs: &HashSet<Revision>, |
|
95 | filtered_revs: &HashSet<Revision>, | |
94 | ) -> Result<(), GraphError> { |
|
96 | ) -> Result<(), GraphError> { | |
95 | for idx in (0..not_heads.len()).rev() { |
|
97 | for idx in (0..not_heads.len()).rev() { | |
96 | let rev = Revision(idx as BaseRevision); |
|
98 | let rev = Revision(idx as BaseRevision); | |
97 | if !not_heads[idx] && filtered_revs.contains(&rev) { |
|
99 | if !not_heads[idx] && filtered_revs.contains(&rev) { | |
98 |
not_heads |
|
100 | not_heads.get_mut(idx).unwrap().commit(true); | |
99 | continue; |
|
101 | continue; | |
100 | } |
|
102 | } | |
101 | for parent in graph.parents(rev)?.iter() { |
|
103 | for parent in graph.parents(rev)?.iter() { | |
102 | if *parent != NULL_REVISION { |
|
104 | if *parent != NULL_REVISION { | |
103 |
not_heads |
|
105 | not_heads.get_mut(parent.0 as usize).unwrap().commit(true); | |
104 | } |
|
106 | } | |
105 | } |
|
107 | } | |
106 | } |
|
108 | } |
@@ -3,6 +3,7 b' use std::fmt::Debug;' | |||||
3 | use std::ops::Deref; |
|
3 | use std::ops::Deref; | |
4 | use std::sync::{RwLock, RwLockReadGuard, RwLockWriteGuard}; |
|
4 | use std::sync::{RwLock, RwLockReadGuard, RwLockWriteGuard}; | |
5 |
|
5 | |||
|
6 | use bitvec::prelude::*; | |||
6 | use byteorder::{BigEndian, ByteOrder}; |
|
7 | use byteorder::{BigEndian, ByteOrder}; | |
7 | use bytes_cast::{unaligned, BytesCast}; |
|
8 | use bytes_cast::{unaligned, BytesCast}; | |
8 |
|
9 | |||
@@ -568,8 +569,12 b' impl Index {' | |||||
568 | let as_vec = if self.is_empty() { |
|
569 | let as_vec = if self.is_empty() { | |
569 | vec![NULL_REVISION] |
|
570 | vec![NULL_REVISION] | |
570 | } else { |
|
571 | } else { | |
571 |
let mut not_heads = vec![ |
|
572 | let mut not_heads = bitvec![0; self.len()]; | |
572 |
dagops::retain_heads_fast( |
|
573 | dagops::retain_heads_fast( | |
|
574 | self, | |||
|
575 | not_heads.as_mut_bitslice(), | |||
|
576 | filtered_revs, | |||
|
577 | )?; | |||
573 | not_heads |
|
578 | not_heads | |
574 | .into_iter() |
|
579 | .into_iter() | |
575 | .enumerate() |
|
580 | .enumerate() |
General Comments 0
You need to be logged in to leave comments.
Login now