Overview
| Comment: | Added a function that reverses the bits in a byte. Coverage: 100.0% of statements. |
|---|---|
| Downloads: | Tarball | ZIP archive |
| Timelines: | family | ancestors | descendants | both | trunk |
| Files: | files | file ages | folders |
| SHA1: |
2be2ff6bf747e4314ac4fa406b98faeb |
| User & Date: | spaskalev on 2014-12-21 01:59:34.533 |
| Other Links: | manifest | tags |
Context
|
2014-12-21
| ||
| 17:23 | Fixed a rare case of losing data from the decompressor's internal result buffer. check-in: 7b74fd57f8 user: spaskalev tags: trunk | |
| 01:59 | Added a function that reverses the bits in a byte. Coverage: 100.0% of statements. check-in: 2be2ff6bf7 user: spaskalev tags: trunk | |
|
2014-12-20
| ||
| 17:44 | Buffer the input on decompressing, not the decompressor itself. This takes pdc -d < linux-3.18.1.tar.pdc > linux-3.18.1.tar down to 11 seconds from 13 minutes :) check-in: 4f0d26907d user: spaskalev tags: trunk | |
Changes
Modified src/0dev.org/bits/bits.go
from [3a25035ac5]
to [7a154cae58].
| ︙ | ︙ | |||
16 17 18 19 20 21 22 | 1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5, 2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6, 2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6, 3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7, 2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6, 3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7, 3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7, | | > > > > > > > > > > > > > > > > > > > > > > > > > | 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5,
2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6,
2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6,
3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7,
2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6,
3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7,
3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7,
4, 5, 5, 6, 5, 6, 6, 7, 5, 6, 6, 7, 6, 7, 7, 8,
}
// Returns the number of raised bits in the given byte
func Hamming(b byte) byte {
return hamming[b]
}
var reversed = [256]byte{
0, 128, 64, 192, 32, 160, 96, 224, 16, 144, 80, 208, 48, 176, 112, 240,
8, 136, 72, 200, 40, 168, 104, 232, 24, 152, 88, 216, 56, 184, 120, 248,
4, 132, 68, 196, 36, 164, 100, 228, 20, 148, 84, 212, 52, 180, 116, 244,
12, 140, 76, 204, 44, 172, 108, 236, 28, 156, 92, 220, 60, 188, 124, 252,
2, 130, 66, 194, 34, 162, 98, 226, 18, 146, 82, 210, 50, 178, 114, 242,
10, 138, 74, 202, 42, 170, 106, 234, 26, 154, 90, 218, 58, 186, 122, 250,
6, 134, 70, 198, 38, 166, 102, 230, 22, 150, 86, 214, 54, 182, 118, 246,
14, 142, 78, 206, 46, 174, 110, 238, 30, 158, 94, 222, 62, 190, 126, 254,
1, 129, 65, 193, 33, 161, 97, 225, 17, 145, 81, 209, 49, 177, 113, 241,
9, 137, 73, 201, 41, 169, 105, 233, 25, 153, 89, 217, 57, 185, 121, 249,
5, 133, 69, 197, 37, 165, 101, 229, 21, 149, 85, 213, 53, 181, 117, 245,
13, 141, 77, 205, 45, 173, 109, 237, 29, 157, 93, 221, 61, 189, 125, 253,
3, 131, 67, 195, 35, 163, 99, 227, 19, 147, 83, 211, 51, 179, 115, 243,
11, 139, 75, 203, 43, 171, 107, 235, 27, 155, 91, 219, 59, 187, 123, 251,
7, 135, 71, 199, 39, 167, 103, 231, 23, 151, 87, 215, 55, 183, 119, 247,
15, 143, 79, 207, 47, 175, 111, 239, 31, 159, 95, 223, 63, 191, 127, 255,
}
// Returns a bits-reversed byte based on the input
func Reverse(b byte) byte {
return reversed[b]
}
// The Vector interface defines methods on the bit vector
type Vector interface {
// Retrieves the bit at the designated position
Peek(uint) bool
// Sets the bit at the designated position
Poke(uint, bool)
|
| ︙ | ︙ |
Modified src/0dev.org/bits/bits_test.go
from [b5ed7a9a33]
to [255f42be62].
| ︙ | ︙ | |||
15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
b = b >> 1
}
if result != Hamming(byte(i)) {
t.Error("Invalid hamming weight reported for ", i)
}
}
}
var sizes []uint = []uint{0, 31, 32, 33, 61, 63, 64, 127, 128, 129}
func TestBitSize(t *testing.T) {
for _, size := range sizes {
v := NewBit(size)
if v.Len() < size || v.Len() > size+strconv.IntSize {
| > > > > > > > > > > > > > > > > > > > | 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
b = b >> 1
}
if result != Hamming(byte(i)) {
t.Error("Invalid hamming weight reported for ", i)
}
}
}
func TestReverse(t *testing.T) {
for i := 0; i < 256; i++ {
input, result := i, byte(0)
for j := 0; j < 7; j++ {
if (input & 1) > 0 {
result |= 1
}
result <<= 1
input >>= 1
}
if (input & 1) > 0 {
result |= 1
}
if result != Reverse(byte(i)) {
t.Error("Invalid reverse byte reported for ", i)
}
}
}
var sizes []uint = []uint{0, 31, 32, 33, 61, 63, 64, 127, 128, 129}
func TestBitSize(t *testing.T) {
for _, size := range sizes {
v := NewBit(size)
if v.Len() < size || v.Len() > size+strconv.IntSize {
|
| ︙ | ︙ |