@@ -1551,7 +1551,7 @@ impl<T: Hash + Eq> HashSet<T, RandomSipHasher> {
1551
1551
/// # Example
1552
1552
///
1553
1553
/// ```rust
1554
- /// # use std::collections::HashSet;
1554
+ /// use std::collections::HashSet;
1555
1555
/// let mut set: HashSet<int> = HashSet::new();
1556
1556
/// ```
1557
1557
#[ inline]
@@ -1565,7 +1565,7 @@ impl<T: Hash + Eq> HashSet<T, RandomSipHasher> {
1565
1565
/// # Example
1566
1566
///
1567
1567
/// ```rust
1568
- /// # use std::collections::HashSet;
1568
+ /// use std::collections::HashSet;
1569
1569
/// let mut set: HashSet<int> = HashSet::with_capacity(10);
1570
1570
/// ```
1571
1571
#[ inline]
@@ -1583,7 +1583,7 @@ impl<T: Eq + Hash<S>, S, H: Hasher<S>> HashSet<T, H> {
1583
1583
/// # Example
1584
1584
///
1585
1585
/// ```rust
1586
- /// # use std::collections::HashSet;
1586
+ /// use std::collections::HashSet;
1587
1587
/// use std::hash::sip::SipHasher;
1588
1588
///
1589
1589
/// let h = SipHasher::new();
@@ -1606,7 +1606,7 @@ impl<T: Eq + Hash<S>, S, H: Hasher<S>> HashSet<T, H> {
1606
1606
/// # Example
1607
1607
///
1608
1608
/// ```rust
1609
- /// # use std::collections::HashSet;
1609
+ /// use std::collections::HashSet;
1610
1610
/// use std::hash::sip::SipHasher;
1611
1611
///
1612
1612
/// let h = SipHasher::new();
@@ -1623,7 +1623,7 @@ impl<T: Eq + Hash<S>, S, H: Hasher<S>> HashSet<T, H> {
1623
1623
/// # Example
1624
1624
///
1625
1625
/// ```rust
1626
- /// # use std::collections::HashSet;
1626
+ /// use std::collections::HashSet;
1627
1627
/// let mut set: HashSet<int> = HashSet::new();
1628
1628
/// set.reserve(10);
1629
1629
/// ```
@@ -1641,7 +1641,7 @@ impl<T: Eq + Hash<S>, S, H: Hasher<S>> HashSet<T, H> {
1641
1641
/// values hash the same, which is why we implement `Hash`.
1642
1642
///
1643
1643
/// ```rust
1644
- /// # use std::collections::HashSet;
1644
+ /// use std::collections::HashSet;
1645
1645
/// use std::hash::Hash;
1646
1646
/// use std::hash::sip::SipState;
1647
1647
///
@@ -1682,7 +1682,8 @@ impl<T: Eq + Hash<S>, S, H: Hasher<S>> HashSet<T, H> {
1682
1682
/// # Example
1683
1683
///
1684
1684
/// ```rust
1685
- /// # use std::collections::HashSet;
1685
+ /// use std::collections::HashSet;
1686
+ ///
1686
1687
/// let mut set = HashSet::new();
1687
1688
/// set.insert("a");
1688
1689
/// set.insert("b");
@@ -1703,7 +1704,8 @@ impl<T: Eq + Hash<S>, S, H: Hasher<S>> HashSet<T, H> {
1703
1704
/// # Example
1704
1705
///
1705
1706
/// ```rust
1706
- /// # use std::collections::HashSet;
1707
+ /// use std::collections::HashSet;
1708
+ ///
1707
1709
/// let mut set = HashSet::new();
1708
1710
/// set.insert("a".to_string());
1709
1711
/// set.insert("b".to_string());
@@ -1725,7 +1727,8 @@ impl<T: Eq + Hash<S>, S, H: Hasher<S>> HashSet<T, H> {
1725
1727
/// # Example
1726
1728
///
1727
1729
/// ```rust
1728
- /// # use std::collections::HashSet;
1730
+ /// use std::collections::HashSet;
1731
+ ///
1729
1732
/// let a: HashSet<int> = [1i, 2, 3].iter().map(|&x| x).collect();
1730
1733
/// let b: HashSet<int> = [4i, 2, 3, 4].iter().map(|&x| x).collect();
1731
1734
///
@@ -1754,7 +1757,8 @@ impl<T: Eq + Hash<S>, S, H: Hasher<S>> HashSet<T, H> {
1754
1757
/// # Example
1755
1758
///
1756
1759
/// ```rust
1757
- /// # use std::collections::HashSet;
1760
+ /// use std::collections::HashSet;
1761
+ ///
1758
1762
/// let a: HashSet<int> = [1i, 2, 3].iter().map(|&x| x).collect();
1759
1763
/// let b: HashSet<int> = [4i, 2, 3, 4].iter().map(|&x| x).collect();
1760
1764
///
@@ -1779,7 +1783,8 @@ impl<T: Eq + Hash<S>, S, H: Hasher<S>> HashSet<T, H> {
1779
1783
/// # Example
1780
1784
///
1781
1785
/// ```rust
1782
- /// # use std::collections::HashSet;
1786
+ /// use std::collections::HashSet;
1787
+ ///
1783
1788
/// let a: HashSet<int> = [1i, 2, 3].iter().map(|&x| x).collect();
1784
1789
/// let b: HashSet<int> = [4i, 2, 3, 4].iter().map(|&x| x).collect();
1785
1790
///
@@ -1804,7 +1809,8 @@ impl<T: Eq + Hash<S>, S, H: Hasher<S>> HashSet<T, H> {
1804
1809
/// # Example
1805
1810
///
1806
1811
/// ```rust
1807
- /// # use std::collections::HashSet;
1812
+ /// use std::collections::HashSet;
1813
+ ///
1808
1814
/// let a: HashSet<int> = [1i, 2, 3].iter().map(|&x| x).collect();
1809
1815
/// let b: HashSet<int> = [4i, 2, 3, 4].iter().map(|&x| x).collect();
1810
1816
///
@@ -1823,22 +1829,6 @@ impl<T: Eq + Hash<S>, S, H: Hasher<S>> HashSet<T, H> {
1823
1829
}
1824
1830
1825
1831
impl < T : Eq + Hash < S > , S , H : Hasher < S > > PartialEq for HashSet < T , H > {
1826
- /// Partial equality between sets.
1827
- ///
1828
- /// # Example
1829
- ///
1830
- /// ```rust
1831
- /// # use std::collections::HashSet;
1832
- /// let a: HashSet<int> = [1i, 2, 3].iter().map(|&x| x).collect();
1833
- /// let b: HashSet<int> = [1i, 2, 3, 4].iter().map(|&x| x).collect();
1834
- /// let c: HashSet<int> = [1i, 2, 3].iter().map(|&x| x).collect();
1835
- ///
1836
- /// assert!(a.eq(&c));
1837
- ///
1838
- /// // eq and ne defines the == and != operators
1839
- /// assert!(a == c);
1840
- /// assert!(a != b);
1841
- /// ```
1842
1832
fn eq ( & self , other : & HashSet < T , H > ) -> bool {
1843
1833
if self . len ( ) != other. len ( ) { return false ; }
1844
1834
@@ -1849,127 +1839,33 @@ impl<T: Eq + Hash<S>, S, H: Hasher<S>> PartialEq for HashSet<T, H> {
1849
1839
impl < T : Eq + Hash < S > , S , H : Hasher < S > > Eq for HashSet < T , H > { }
1850
1840
1851
1841
impl < T : Eq + Hash < S > , S , H : Hasher < S > > Collection for HashSet < T , H > {
1852
- /// Return the number of elements in the set.
1853
- ///
1854
- /// # Example
1855
- ///
1856
- /// ```rust
1857
- /// # use std::collections::HashSet;
1858
- /// let set: HashSet<int> = [1i, 2, 3, 2].iter().map(|&x| x).collect();
1859
- /// assert_eq!(set.len(), 3);
1860
- /// ```
1861
1842
fn len ( & self ) -> uint { self . map . len ( ) }
1862
1843
}
1863
1844
1864
1845
impl < T : Eq + Hash < S > , S , H : Hasher < S > > Mutable for HashSet < T , H > {
1865
- /// Clear the set. Keeps the allocated memory for reuse.
1866
- ///
1867
- /// # Example
1868
- ///
1869
- /// ```rust
1870
- /// # use std::collections::HashSet;
1871
- /// let mut set: HashSet<int> = [1i, 2, 3].iter().map(|&x| x).collect();
1872
- /// set.clear();
1873
- /// assert!(set.is_empty());
1874
- /// ```
1875
1846
fn clear ( & mut self ) { self . map . clear ( ) }
1876
1847
}
1877
1848
1878
1849
impl < T : Eq + Hash < S > , S , H : Hasher < S > > Set < T > for HashSet < T , H > {
1879
- /// Return true if `value` is contained by the set.
1880
- ///
1881
- /// # Example
1882
- ///
1883
- /// ```rust
1884
- /// # use std::collections::HashSet;
1885
- /// let set: HashSet<int> = [1i, 2, 3].iter().map(|&x| x).collect();
1886
- /// assert_eq!(set.contains(&1), true);
1887
- /// assert_eq!(set.contains(&4), false);
1888
- /// ```
1889
1850
fn contains ( & self , value : & T ) -> bool { self . map . contains_key ( value) }
1890
1851
1891
- /// Return true if the set is disjoint with `other`.
1892
- ///
1893
- /// # Example
1894
- ///
1895
- /// ```rust
1896
- /// # use std::collections::HashSet;
1897
- /// let a: HashSet<int> = [1i, 2, 3].iter().map(|&x| x).collect();
1898
- /// let mut b: HashSet<int> = HashSet::new();
1899
- ///
1900
- /// assert_eq!(a.is_disjoint(&b), true);
1901
- /// b.insert(4);
1902
- /// assert_eq!(a.is_disjoint(&b), true);
1903
- /// b.insert(1);
1904
- /// assert_eq!(a.is_disjoint(&b), false);
1905
- /// ```
1906
1852
fn is_disjoint ( & self , other : & HashSet < T , H > ) -> bool {
1907
1853
self . iter ( ) . all ( |v| !other. contains ( v) )
1908
1854
}
1909
1855
1910
- /// Return true if the set is a subset of `other`.
1911
- ///
1912
- /// # Example
1913
- ///
1914
- /// ```rust
1915
- /// # use std::collections::HashSet;
1916
- /// let sup: HashSet<int> = [1i, 2, 3].iter().map(|&x| x).collect();
1917
- /// let mut set: HashSet<int> = HashSet::new();
1918
- ///
1919
- /// assert_eq!(set.is_subset(&sup), true);
1920
- /// set.insert(2);
1921
- /// assert_eq!(set.is_subset(&sup), true);
1922
- /// set.insert(4);
1923
- /// assert_eq!(set.is_subset(&sup), false);
1924
- /// ```
1925
1856
fn is_subset ( & self , other : & HashSet < T , H > ) -> bool {
1926
1857
self . iter ( ) . all ( |v| other. contains ( v) )
1927
1858
}
1928
1859
}
1929
1860
1930
1861
impl < T : Eq + Hash < S > , S , H : Hasher < S > > MutableSet < T > for HashSet < T , H > {
1931
- /// Insert an element.
1932
- ///
1933
- /// # Example
1934
- ///
1935
- /// ```rust
1936
- /// # use std::collections::HashSet;
1937
- /// let mut set = HashSet::new();
1938
- /// set.insert(2i);
1939
- /// set.insert(2i);
1940
- /// assert_eq!(set.len(), 1);
1941
- /// ```
1942
1862
fn insert ( & mut self , value : T ) -> bool { self . map . insert ( value, ( ) ) }
1943
1863
1944
- /// Remove an element.
1945
- ///
1946
- /// # Example
1947
- ///
1948
- /// ```rust
1949
- /// # use std::collections::HashSet;
1950
- /// let mut set = HashSet::new();
1951
- /// set.insert(2i);
1952
- ///
1953
- /// // Return boolean success flag.
1954
- /// assert_eq!(set.remove(&2), true);
1955
- /// assert_eq!(set.remove(&2), false);
1956
- /// ```
1957
1864
fn remove ( & mut self , value : & T ) -> bool { self . map . remove ( value) }
1958
1865
}
1959
1866
1960
1867
1961
1868
impl < T : Eq + Hash < S > + fmt:: Show , S , H : Hasher < S > > fmt:: Show for HashSet < T , H > {
1962
- /// Implement the `Show` trait for easy output format. The values in the
1963
- /// set must also implement `Show`.
1964
- ///
1965
- /// # Example
1966
- ///
1967
- /// ```rust
1968
- /// # use std::collections::HashSet;
1969
- /// let a: HashSet<int> = [1i, 2, 3].iter().map(|&x| x).collect();
1970
- /// // Will call .fmt() to print, in some order.
1971
- /// println!("{}", a);
1972
- /// ```
1973
1869
fn fmt ( & self , f : & mut fmt:: Formatter ) -> fmt:: Result {
1974
1870
try!( write ! ( f, "{{" ) ) ;
1975
1871
@@ -1983,17 +1879,6 @@ impl<T: Eq + Hash<S> + fmt::Show, S, H: Hasher<S>> fmt::Show for HashSet<T, H> {
1983
1879
}
1984
1880
1985
1881
impl < T : Eq + Hash < S > , S , H : Hasher < S > + Default > FromIterator < T > for HashSet < T , H > {
1986
- /// Build a set from an external iterator.
1987
- ///
1988
- /// # Example
1989
- ///
1990
- /// ```rust
1991
- /// # use std::collections::HashSet;
1992
- /// let values = vec!(1i, 2, 3);
1993
- /// let set: HashSet<int> = values.move_iter().collect();
1994
- /// let another_set: HashSet<int> = [1i, 2, 3].iter().map(|&x| x).collect();
1995
- /// assert_eq!(set, another_set);
1996
- /// ```
1997
1882
fn from_iter < I : Iterator < T > > ( iter : I ) -> HashSet < T , H > {
1998
1883
let ( lower, _) = iter. size_hint ( ) ;
1999
1884
let mut set = HashSet :: with_capacity_and_hasher ( lower, Default :: default ( ) ) ;
@@ -2003,18 +1888,6 @@ impl<T: Eq + Hash<S>, S, H: Hasher<S> + Default> FromIterator<T> for HashSet<T,
2003
1888
}
2004
1889
2005
1890
impl < T : Eq + Hash < S > , S , H : Hasher < S > + Default > Extendable < T > for HashSet < T , H > {
2006
- /// Extend the set with the values yielded by an iterator.
2007
- ///
2008
- /// # Example
2009
- ///
2010
- /// ```rust
2011
- /// # use std::collections::HashSet;
2012
- /// let values = vec!(1i, 2, 3);
2013
- /// let mut set = HashSet::new();
2014
- /// set.insert(0i);
2015
- /// set.extend(values.move_iter());
2016
- /// assert_eq!(set.len(), 4);
2017
- /// ```
2018
1891
fn extend < I : Iterator < T > > ( & mut self , mut iter : I ) {
2019
1892
for k in iter {
2020
1893
self . insert ( k) ;
@@ -2023,15 +1896,6 @@ impl<T: Eq + Hash<S>, S, H: Hasher<S> + Default> Extendable<T> for HashSet<T, H>
2023
1896
}
2024
1897
2025
1898
impl < T : Eq + Hash < S > , S , H : Hasher < S > + Default > Default for HashSet < T , H > {
2026
- /// Create a default set.
2027
- ///
2028
- /// # Example
2029
- ///
2030
- /// ```rust
2031
- /// # use std::collections::HashSet;
2032
- /// use std::default::Default;
2033
- /// let mut set: HashSet<int> = Default::default();
2034
- /// ```
2035
1899
fn default ( ) -> HashSet < T , H > {
2036
1900
HashSet :: with_hasher ( Default :: default ( ) )
2037
1901
}
5 commit comments
bors commentedon Jul 19, 2014
saw approval from alexcrichton
at https://github.com/treeman/rust/commit/01b6fd3e82f84a504f37597152c39da9929fbfbf
bors commentedon Jul 19, 2014
merging treeman/rust/hashset-doc = 01b6fd3 into auto
bors commentedon Jul 19, 2014
treeman/rust/hashset-doc = 01b6fd3 merged ok, testing candidate = 793b142
bors commentedon Jul 19, 2014
all tests pass:
success: http://buildbot.rust-lang.org/builders/auto-mac-32-opt/builds/414
success: http://buildbot.rust-lang.org/builders/auto-mac-64-opt/builds/415
success: http://buildbot.rust-lang.org/builders/auto-mac-64-nopt-c/builds/414
success: http://buildbot.rust-lang.org/builders/auto-mac-64-nopt-t/builds/415
success: http://buildbot.rust-lang.org/builders/auto-linux-32-opt/builds/417
success: http://buildbot.rust-lang.org/builders/auto-linux-32-nopt-c/builds/418
success: http://buildbot.rust-lang.org/builders/auto-linux-32-nopt-t/builds/417
success: http://buildbot.rust-lang.org/builders/auto-linux-64-opt/builds/423
success: http://buildbot.rust-lang.org/builders/auto-linux-64-nopt-c/builds/418
success: http://buildbot.rust-lang.org/builders/auto-linux-64-nopt-t/builds/417
success: http://buildbot.rust-lang.org/builders/auto-linux-64-x-android-t/builds/420
success: http://buildbot.rust-lang.org/builders/auto-win-32-opt/builds/418
success: http://buildbot.rust-lang.org/builders/auto-win-32-nopt-t/builds/418
success: http://buildbot.rust-lang.org/builders/auto-win-32-nopt-c/builds/419
bors commentedon Jul 19, 2014
fast-forwarding master to auto = 793b142