Skip to content

Commit cc53658

Browse files
committed
---
yaml --- r: 30505 b: refs/heads/incoming c: 37cf649 h: refs/heads/master i: 30503: dea0a7f v: v3
1 parent a6e420f commit cc53658

File tree

4 files changed

+62
-2
lines changed

4 files changed

+62
-2
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ refs/heads/try: d324a424d8f84b1eb049b12cf34182bda91b0024
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/ndm: f3868061cd7988080c30d6d5bf352a5a5fe2460b
88
refs/heads/try2: d0c6ce338884ee21843f4b40bf6bf18d222ce5df
9-
refs/heads/incoming: 7a6df9c90ff1042c07bf785b724884fb84df195f
9+
refs/heads/incoming: 37cf649311bcf6fec2d9096b483ac4be81b70732
1010
refs/heads/dist-snap: 2f32a1581f522e524009138b33b1c7049ced668d
1111
refs/tags/release-0.2: c870d2dffb391e14efb05aa27898f1f6333a9596
1212
refs/tags/release-0.3: b5f0d0f648d9a6153664837026ba1be43d3e2503

branches/incoming/src/libcore/cmp.rs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,14 @@
55
/// Interfaces used for comparison.
66
77
// 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+
*/
816
#[cfg(notest)]
917
#[lang="ord"]
1018
trait Ord {
@@ -24,6 +32,14 @@ trait Ord {
2432

2533
#[cfg(notest)]
2634
#[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+
*/
2743
trait Eq {
2844
pure fn eq(&&other: self) -> bool;
2945
pure fn ne(&&other: self) -> bool;

branches/incoming/src/libcore/hash.rs

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,31 @@ export hash_u16;
3434
export hash_u8;
3535
export hash_uint;
3636

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+
*/
3849
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+
*/
3962
pure fn hash_keyed(k0: u64, k1: u64) -> u64;
4063
}
4164

branches/incoming/src/libcore/to_bytes.rs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,28 @@ use io::Writer;
66

77
type Cb = fn(buf: &[const u8]) -> bool;
88

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+
*/
916
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+
*/
1031
pure fn iter_bytes(lsb0: bool, f: Cb);
1132
}
1233

0 commit comments

Comments
 (0)