Skip to content

Commit dd0e5d6

Browse files
committed
Changed default hasher for std::collections::HashSet on fnv::FnvHasher and made some functions generic over std::hash::BuildHashser to accept HashSets with any kind of hashers
1 parent 93e7083 commit dd0e5d6

File tree

4 files changed

+21
-17
lines changed

4 files changed

+21
-17
lines changed

src/graph/algo.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -191,8 +191,8 @@ fn cropped_area_of_widget_maybe_within_depth(graph: &Graph,
191191
/// FIXME: This currently uses call stack recursion to do a depth-first search through all
192192
/// depth_children for the total bounding box. This should use a proper `Dfs` type with it's own
193193
/// stack for safer traversal that won't blow the stack on hugely deep GUIs.
194-
pub fn kids_bounding_box(graph: &Graph,
195-
prev_updated: &std::collections::HashSet<widget::Id>,
194+
pub fn kids_bounding_box<T: std::hash::BuildHasher>(graph: &Graph,
195+
prev_updated: &std::collections::HashSet<widget::Id, T>,
196196
idx: widget::Id) -> Option<Rect>
197197
{
198198
// When traversing the `depth_kids`, we only want to visit those who:

src/graph/depth_order.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,10 +49,10 @@ impl DepthOrder {
4949
///
5050
/// The `visit_by_depth` algorithm should not be recursive and instead use either looping,
5151
/// walking or iteration.
52-
pub fn update(&mut self,
52+
pub fn update<T: std::hash::BuildHasher>(&mut self,
5353
graph: &Graph,
5454
root: widget::Id,
55-
updated_widgets: &std::collections::HashSet<widget::Id>)
55+
updated_widgets: &std::collections::HashSet<widget::Id, T>)
5656
{
5757
let DepthOrder { ref mut indices, ref mut floating } = *self;
5858

@@ -88,9 +88,9 @@ impl DepthOrder {
8888

8989

9090
/// Recursive function for visiting all nodes within the dag.
91-
fn visit_by_depth(graph: &Graph,
91+
fn visit_by_depth<T: std::hash::BuildHasher>(graph: &Graph,
9292
idx: widget::Id,
93-
updated_widgets: &std::collections::HashSet<widget::Id>,
93+
updated_widgets: &std::collections::HashSet<widget::Id, T>,
9494
depth_order: &mut Vec<widget::Id>,
9595
floating_deque: &mut Vec<widget::Id>)
9696
{

src/ui.rs

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ use input;
55
use position::{self, Align, Direction, Dimensions, Padding, Point, Position, Range, Rect, Scalar};
66
use render;
77
use std;
8+
use fnv;
89
use text;
910
use theme::Theme;
1011
use utils;
@@ -67,12 +68,12 @@ pub struct Ui {
6768
/// The order in which widgets from the `widget_graph` are drawn.
6869
depth_order: graph::DepthOrder,
6970
/// The set of widgets that have been updated since the beginning of the `set_widgets` stage.
70-
updated_widgets: std::collections::HashSet<widget::Id>,
71+
updated_widgets: fnv::FnvHashSet<widget::Id>,
7172
/// The `updated_widgets` for the previous `set_widgets` stage.
7273
///
7374
/// We use this to compare against the newly generated `updated_widgets` to see whether or not
7475
/// we require re-drawing.
75-
prev_updated_widgets: std::collections::HashSet<widget::Id>,
76+
prev_updated_widgets: fnv::FnvHashSet<widget::Id>,
7677
/// Scroll events that have been emitted during a call to `Ui::set_widgets`. These are usually
7778
/// emitted by some widget like the `Scrollbar`.
7879
///
@@ -172,10 +173,11 @@ impl Ui {
172173
maybe_widgets_capacity.map_or_else(
173174
|| (Graph::new(),
174175
graph::DepthOrder::new(),
175-
std::collections::HashSet::new()),
176+
fnv::FnvHashSet::default()),
176177
|n| (Graph::with_node_capacity(n),
177178
graph::DepthOrder::with_node_capacity(n),
178-
std::collections::HashSet::with_capacity(n)));
179+
std::collections::HashSet::with_capacity_and_hasher(n,
180+
fnv::FnvBuildHasher::default())));
179181

180182
let window = widget_graph.add_placeholder();
181183
let prev_updated_widgets = updated_widgets.clone();
@@ -270,15 +272,15 @@ impl Ui {
270272
///
271273
/// This set indicates which widgets have been instantiated since the beginning of the most
272274
/// recent `Ui::set_widgets` call.
273-
pub fn updated_widgets(&self) -> &std::collections::HashSet<widget::Id> {
275+
pub fn updated_widgets(&self) -> &fnv::FnvHashSet<widget::Id> {
274276
&self.updated_widgets
275277
}
276278

277279
/// Borrow the **Ui**'s set of updated widgets.
278280
///
279281
/// This set indicates which widgets have were instantiated during the previous call to
280282
/// `Ui::set_widgets`.
281-
pub fn prev_updated_widgets(&self) -> &std::collections::HashSet<widget::Id> {
283+
pub fn prev_updated_widgets(&self) -> &fnv::FnvHashSet<widget::Id> {
282284
&self.prev_updated_widgets
283285
}
284286

src/widget/list_select.rs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -120,15 +120,15 @@ pub struct Multiple;
120120

121121
/// Represents some change in item selection for a `ListSelect` in `Multiple` mode.
122122
#[derive(Clone, Debug)]
123-
pub enum Selection {
123+
pub enum Selection<H: std::hash::BuildHasher = std::collections::hash_map::RandomState> {
124124
/// Items which have been added to the selection.
125-
Add(std::collections::HashSet<usize>),
125+
Add(std::collections::HashSet<usize, H>),
126126
/// Items which have been removed from the selection.
127-
Remove(std::collections::HashSet<usize>),
127+
Remove(std::collections::HashSet<usize, H>),
128128
}
129129

130130

131-
impl Selection {
131+
impl<H: std::hash::BuildHasher> Selection<H> {
132132

133133
/// Update the given slice of `bool`s with this `Selection`.
134134
///
@@ -151,7 +151,9 @@ impl Selection {
151151
}
152152

153153
/// Update the given set of selected indices with this `Selection`.
154-
pub fn update_index_set(&self, set: &mut std::collections::HashSet<usize>) {
154+
pub fn update_index_set<T>(&self, set: &mut std::collections::HashSet<usize, T>)
155+
where T: std::hash::BuildHasher
156+
{
155157
match *self {
156158
Selection::Add(ref indices) =>
157159
for &i in indices {

0 commit comments

Comments
 (0)