This commit is contained in:
2018-02-06 11:16:42 +01:00
parent 96720c83e7
commit a62326cdb3
4 changed files with 94 additions and 12 deletions

View File

@@ -1,3 +1,4 @@
extern crate ordermap;
extern crate rayon;
extern crate serde;
extern crate unreachable;
@@ -8,6 +9,7 @@ use std::iter::{FromIterator, IntoIterator, Iterator};
use std::default::Default;
use std::collections::{HashMap, LinkedList};
use ordermap::OrderMap;
use rayon::iter::{FromParallelIterator, IntoParallelIterator, ParallelExtend, ParallelIterator};
use serde::{Deserialize, Deserializer, Serialize, Serializer};
@@ -22,6 +24,7 @@ const BITS: u64 = 64;
type Block = u64;
type Storage = HashMap<u64, Block, BitBuildHasher>;
// type Storage = OrderMap<u64, Block, BitBuildHasher>;
pub type BitHashMap<V> = HashMap<u64, V, BitBuildHasher>;
@@ -64,7 +67,7 @@ impl BitSet {
pub fn shrink_to_fit(&mut self) {
self.blocks.retain(|_, block| *block != 0);
self.blocks.shrink_to_fit()
// self.blocks.shrink_to_fit();
}
pub fn iter(&self) -> Iter {
@@ -246,6 +249,27 @@ impl<'a> ops::BitOr<&'a Self> for BitSet {
}
}
impl<'a> ops::BitOr<&'a BitSet> for &'a BitSet {
type Output = BitSet;
#[inline]
fn bitor(self, rhs: &'a BitSet) -> BitSet {
let mut set = self.clone();
for (key, value) in &rhs.blocks {
let block = set.blocks.entry(*key).or_insert(0);
let n = block.count_ones();
*block |= value;
set.nbits += (block.count_ones() - n) as usize;
}
set
}
}
impl<'a> ops::Sub<&'a BitSet> for &'a BitSet {
type Output = BitSet;
@@ -269,6 +293,7 @@ impl<'a> ops::Sub<&'a BitSet> for &'a BitSet {
pub struct Iter<'a> {
iter: std::collections::hash_map::Iter<'a, u64, u64>,
// iter: ordermap::Iter<'a, u64, u64>,
block: u64,
bits: u64,
bit: u64,
@@ -276,6 +301,7 @@ pub struct Iter<'a> {
pub struct IntoIter {
iter: std::collections::hash_map::IntoIter<u64, u64>,
// iter: ordermap::IntoIter<u64, u64>,
block: u64,
bits: u64,
bit: u64,