pub struct RangeMinimumQuery<T> {
data: Vec<T>,
suffix: Vec<T>,
prefix: Vec<T>,
table: Vec<T>,
blocks: usize,
}Fields§
§data: Vec<T>§suffix: Vec<T>§prefix: Vec<T>§table: Vec<T>§blocks: usizeImplementations§
Source§impl<T> RangeMinimumQuery<T>
impl<T> RangeMinimumQuery<T>
Sourcepub fn new(data: Vec<T>) -> Self
pub fn new(data: Vec<T>) -> Self
Examples found in repository?
More examples
crates/competitive/src/string/string_search.rs (line 74)
70 pub fn new(text: Vec<T>) -> Self {
71 let suffix_array = SuffixArray::new(&text);
72
73 let (lcp_array, rank) = suffix_array.lcp_array_with_rank(&text);
74 let rmq = RangeMinimumQuery::new(lcp_array.clone());
75
76 Self {
77 text,
78 suffix_array,
79 lcp_array,
80 rank,
81 rmq,
82 }
83 }crates/competitive/src/tree/euler_tour.rs (line 302)
247 pub fn from_parents(parents: &[usize]) -> Self {
248 let n = parents.len();
249 let root = parents.iter().position(|&parent| parent == !0).unwrap();
250 let mut depth = vec![!0u32; n];
251 depth[root] = 0;
252 let mut label_to_node = Vec::with_capacity(n);
253 let mut node_to_label = vec![0u32; n];
254 label_to_node.push(root as u32);
255 let mut path = Vec::new();
256 for mut u in 0..n {
257 if depth[u] != !0 {
258 continue;
259 }
260 if depth[parents[u]] != !0 {
261 depth[u] = depth[parents[u]] + 1;
262 node_to_label[u] = label_to_node.len() as u32;
263 label_to_node.push(u as u32);
264 continue;
265 }
266 while depth[u] == !0 {
267 path.push(u);
268 u = parents[u];
269 }
270 while let Some(u) = path.pop() {
271 depth[u] = depth[parents[u]] + 1;
272 node_to_label[u] = label_to_node.len() as u32;
273 label_to_node.push(u as u32);
274 }
275 }
276
277 let mut label_to_index = vec![0u32; n];
278 for i in (1..n).rev() {
279 let u = label_to_node[i] as usize;
280 let parent = node_to_label[parents[u]] as usize;
281 label_to_index[parent] += label_to_index[i] + 1;
282 }
283 for i in 1..n {
284 let u = label_to_node[i] as usize;
285 let parent = node_to_label[parents[u]] as usize;
286 let descendants = label_to_index[i];
287 let next = label_to_index[parent];
288 label_to_index[i] = next;
289 label_to_index[parent] = next - descendants - 1;
290 }
291
292 let mut index_to_parent = vec![0u32; n];
293 for label in (1..n).rev() {
294 let u = label_to_node[label] as usize;
295 index_to_parent[label_to_index[label] as usize] = node_to_label[parents[u]];
296 node_to_label[u] = label_to_index[label];
297 }
298
299 Self {
300 node_to_index: node_to_label,
301 label_to_node,
302 rmq: RangeMinimumQuery::new(index_to_parent),
303 depth,
304 }
305 }
306
307 /// `order` must be a DFS preorder containing every vertex in `parents` exactly once.
308 /// `parents` uses `!0` for the root.
309 pub fn from_dfs_preorder(parents: &[usize], order: &[usize]) -> Self {
310 let n = parents.len();
311 let mut node_to_index = vec![0u32; n];
312 for (i, &u) in order.iter().enumerate() {
313 node_to_index[u] = i as u32;
314 }
315 let mut depth = vec![0u32; n];
316 let mut index_to_parent = vec![0u32; n];
317 for (i, &u) in order.iter().enumerate().skip(1) {
318 let p = parents[u];
319 depth[u] = depth[p] + 1;
320 index_to_parent[i] = node_to_index[p];
321 }
322 Self {
323 node_to_index,
324 label_to_node: order.iter().map(|&u| u as u32).collect(),
325 rmq: RangeMinimumQuery::new(index_to_parent),
326 depth,
327 }
328 }Trait Implementations§
Source§impl<T: Clone> Clone for RangeMinimumQuery<T>
impl<T: Clone> Clone for RangeMinimumQuery<T>
Auto Trait Implementations§
impl<T> Freeze for RangeMinimumQuery<T>
impl<T> RefUnwindSafe for RangeMinimumQuery<T>where
Vec<T>: RefUnwindSafe,
impl<T> Send for RangeMinimumQuery<T>
impl<T> Sync for RangeMinimumQuery<T>
impl<T> Unpin for RangeMinimumQuery<T>
impl<T> UnsafeUnpin for RangeMinimumQuery<T>where
Vec<T>: UnsafeUnpin,
impl<T> UnwindSafe for RangeMinimumQuery<T>where
Vec<T>: UnwindSafe,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more