File tree Expand file tree Collapse file tree 4 files changed +62
-2
lines changed Expand file tree Collapse file tree 4 files changed +62
-2
lines changed Original file line number Diff line number Diff line change 2
2
refs/heads/master: cd6f24f9d14ac90d167386a56e7a6ac1f0318195
3
3
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
4
4
refs/heads/snap-stage3: cd6f24f9d14ac90d167386a56e7a6ac1f0318195
5
- refs/heads/try: 7a6df9c90ff1042c07bf785b724884fb84df195f
5
+ refs/heads/try: 37cf649311bcf6fec2d9096b483ac4be81b70732
6
6
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
7
7
refs/heads/ndm: f3868061cd7988080c30d6d5bf352a5a5fe2460b
8
8
refs/heads/try2: d0c6ce338884ee21843f4b40bf6bf18d222ce5df
Original file line number Diff line number Diff line change 5
5
/// Interfaces used for comparison.
6
6
7
7
// Awful hack to work around duplicate lang items in core test.
8
+
9
+ /**
10
+ * Trait for values that can be compared for a sort-order.
11
+ *
12
+ * Eventually this may be simplified to only require
13
+ * an `le` method, with the others generated from
14
+ * default implementations.
15
+ */
8
16
#[ cfg( notest) ]
9
17
#[ lang="ord" ]
10
18
trait Ord {
@@ -24,6 +32,14 @@ trait Ord {
24
32
25
33
#[ cfg( notest) ]
26
34
#[ lang="eq" ]
35
+ /**
36
+ * Trait for values that can be compared for equality
37
+ * and inequality.
38
+ *
39
+ * Eventually this may be simplified to only require
40
+ * an `eq` method, with the other generated from
41
+ * a default implementation.
42
+ */
27
43
trait Eq {
28
44
pure fn eq ( & & other: self ) -> bool ;
29
45
pure fn ne ( & & other: self ) -> bool ;
Original file line number Diff line number Diff line change @@ -34,8 +34,31 @@ export hash_u16;
34
34
export hash_u8;
35
35
export hash_uint;
36
36
37
- /// Types that can meaningfully be hashed should implement this.
37
+ /**
38
+ * Types that can meaningfully be hashed should implement this.
39
+ *
40
+ * Note that this trait is likely to change somewhat as it is
41
+ * closely related to `to_bytes::IterBytes` and in almost all
42
+ * cases presently the two are (and must be) used together.
43
+ *
44
+ * In general, most types only need to implement `IterBytes`,
45
+ * and the implementation of `Hash` below will take care of
46
+ * the rest. This is the recommended approach, since constructing
47
+ * good keyed hash functions is quite difficult.
48
+ */
38
49
trait Hash {
50
+ /**
51
+ * Compute a "keyed" hash of the value implementing the trait,
52
+ * taking `k0` and `k1` as "keying" parameters that randomize or
53
+ * otherwise perturb the hash function in such a way that a
54
+ * hash table built using such "keyed hash functions" cannot
55
+ * be made to perform linearly by an attacker controlling the
56
+ * hashtable's contents.
57
+ *
58
+ * In practical terms, we implement this using the SipHash 2-4
59
+ * function and require most types to only implement the
60
+ * IterBytes trait, that feeds SipHash.
61
+ */
39
62
pure fn hash_keyed ( k0 : u64 , k1 : u64 ) -> u64 ;
40
63
}
41
64
Original file line number Diff line number Diff line change @@ -6,7 +6,28 @@ use io::Writer;
6
6
7
7
type Cb = fn ( buf : & [ const u8 ] ) -> bool ;
8
8
9
+ /**
10
+ * A trait to implement in order to make a type hashable;
11
+ * This works in combination with the trait `Hash::Hash`, and
12
+ * may in the future be merged with that trait or otherwise
13
+ * modified when default methods and trait inheritence are
14
+ * completed.
15
+ */
9
16
trait IterBytes {
17
+ /**
18
+ * Call the provided callback `f` one or more times with
19
+ * byte-slices that should be used when computing a hash
20
+ * value or otherwise "flattening" the structure into
21
+ * a sequence of bytes. The `lsb0` parameter conveys
22
+ * whether the caller is asking for little-endian bytes
23
+ * (`true`) or big-endian (`false`); this should only be
24
+ * relevant in implementations that represent a single
25
+ * multi-byte datum such as a 32 bit integer or 64 bit
26
+ * floating-point value. It can be safely ignored for
27
+ * larger structured types as they are usually processed
28
+ * left-to-right in declaration order, regardless of
29
+ * underlying memory endianness.
30
+ */
10
31
pure fn iter_bytes ( lsb0 : bool , f : Cb ) ;
11
32
}
12
33
You can’t perform that action at this time.
0 commit comments