|
| 1 | +// Copyright 2018 The Rust Project Developers. See the COPYRIGHT |
| 2 | +// file at the top-level directory of this distribution and at |
| 3 | +// http://rust-lang.org/COPYRIGHT. |
| 4 | +// |
| 5 | +// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or |
| 6 | +// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license |
| 7 | +// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your |
| 8 | +// option. This file may not be copied, modified, or distributed |
| 9 | +// except according to those terms. |
| 10 | + |
| 11 | +use crate::facts::{Point, Region}; |
| 12 | +use fxhash::FxHashMap; |
| 13 | + |
| 14 | +#[derive(Clone, Debug)] |
| 15 | +crate struct RegionDegrees { |
| 16 | + in_degree: FxHashMap<(Region, Point), usize>, |
| 17 | + out_degree: FxHashMap<(Region, Point), usize>, |
| 18 | +} |
| 19 | + |
| 20 | +impl RegionDegrees { |
| 21 | + crate fn new() -> Self { |
| 22 | + Self { |
| 23 | + in_degree: Default::default(), |
| 24 | + out_degree: Default::default(), |
| 25 | + } |
| 26 | + } |
| 27 | + |
| 28 | + crate fn update_degrees(&mut self, r1: Region, r2: Region, p: Point) { |
| 29 | + *self.in_degree.entry((r2, p)).or_insert(0) += 1; |
| 30 | + *self.out_degree.entry((r1, p)).or_insert(0) += 1; |
| 31 | + } |
| 32 | + |
| 33 | + crate fn max_out_degree(&self) -> usize { |
| 34 | + *self.out_degree.values().max().unwrap_or(&0) |
| 35 | + } |
| 36 | + |
| 37 | + crate fn max_in_degree(&self) -> usize { |
| 38 | + *self.in_degree.values().max().unwrap_or(&0) |
| 39 | + } |
| 40 | + |
| 41 | + crate fn has_multidegree(&self) -> bool { |
| 42 | + for (region_point, in_count) in &self.in_degree { |
| 43 | + match self.out_degree.get(region_point) { |
| 44 | + Some(out_count) => if *out_count > 1 && *in_count > 1 { |
| 45 | + return true; |
| 46 | + } |
| 47 | + None => {} |
| 48 | + } |
| 49 | + } |
| 50 | + return false; |
| 51 | + } |
| 52 | +} |
0 commit comments