Skip to content

Commit 4542fd4

Browse files
committed
Fix some cases
1 parent cdc4ea7 commit 4542fd4

File tree

4 files changed

+110
-29
lines changed

4 files changed

+110
-29
lines changed

v1/api_test.go

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,99 @@ func TestInsertBooleans(t *testing.T) {
175175
}
176176
}
177177
}
178+
func TestInsertIntegersActive(t *testing.T) {
179+
{
180+
m := map[string]uint64{
181+
"active": 1,
182+
"inactive": 0,
183+
}
184+
b := Make(m, 1)
185+
for k, v := range m {
186+
valb := GetBool(b, k)
187+
if (v != 0) != valb {
188+
t.Fatalf("Insert Integers Active returned %v for %s want %v", valb, k, v)
189+
}
190+
val := uint64(GetNum(b, 1, k))
191+
if v != val {
192+
t.Fatalf("Insert Integers Active returned %v for %s want %v", val, k, v)
193+
}
194+
195+
}
196+
}
197+
{
198+
m := map[string]uint64{
199+
"S0t6lRZL": 1,
200+
"kSix4YCB": 0,
201+
}
202+
b := Make(m, 1)
203+
for k, v := range m {
204+
valb := GetBool(b, k)
205+
if (v != 0) != valb {
206+
t.Fatalf("Insert Integers Active returned %v for %s want %v", valb, k, v)
207+
}
208+
val := uint64(GetNum(b, 1, k))
209+
if v != val {
210+
t.Fatalf("Insert Integers Active returned %v for %s want %v", val, k, v)
211+
}
212+
213+
}
214+
}
215+
{
216+
m := map[string]uint64{
217+
"NDD63C2T": 1,
218+
"yAVmNkB3": 0,
219+
}
220+
b := Make(m, 1)
221+
for k, v := range m {
222+
valb := GetBool(b, k)
223+
if (v != 0) != valb {
224+
t.Fatalf("Insert Integers Active returned %v for %s want %v", valb, k, v)
225+
}
226+
val := uint64(GetNum(b, 1, k))
227+
if v != val {
228+
t.Fatalf("Insert Integers Active returned %v for %s want %v", val, k, v)
229+
}
230+
231+
}
232+
}
233+
{
234+
m := map[string]uint64{
235+
"MdR8DAqA": 0,
236+
"hgPXP3o6": 1,
237+
}
238+
b := Make(m, 1)
239+
for k, v := range m {
240+
valb := GetBool(b, k)
241+
if (v != 0) != valb {
242+
t.Fatalf("Insert Integers Active returned %v for %s want %v", valb, k, v)
243+
}
244+
val := uint64(GetNum(b, 1, k))
245+
if v != val {
246+
t.Fatalf("Insert Integers Active returned %v for %s want %v", val, k, v)
247+
}
248+
249+
}
250+
}
251+
{
252+
m := map[string]uint64{
253+
"S0t6lRZL": 0,
254+
"lyBFeCmp": 1,
255+
}
256+
b := Make(m, 1)
257+
for k, v := range m {
258+
valb := GetBool(b, k)
259+
if (v != 0) != valb {
260+
t.Fatalf("Insert Integers Active returned %v for %s want %v", valb, k, v)
261+
}
262+
val := uint64(GetNum(b, 1, k))
263+
if v != val {
264+
t.Fatalf("Insert Integers Active returned %v for %s want %v", val, k, v)
265+
}
266+
267+
}
268+
}
269+
}
270+
178271
func TestInsertIntegers(t *testing.T) {
179272
{
180273
m := map[string]uint8{

v1/create.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ func create(data map[string][]byte, bitLimit byte) (filter []byte) {
4545
for {
4646
var is_mutated = true
4747
var load uint64
48-
for is_mutated {
48+
for is_mutated && load < maxLoad {
4949
var new_inserted uint64
5050
inner1:
5151
for k, v := range data {

v1/load.go

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,7 @@ func get(f []byte, data []byte, anslen uint64) (ret []byte) {
1212
return nil
1313
}
1414
var datb [64]byte
15-
if len(data) > 63 {
16-
datb = sha512.Sum512(data)
17-
} else {
18-
copy(datb[:], data)
19-
datb[63] = byte(len(data))
20-
for i := range datb {
21-
datb[(i+1)&63] ^= datb[i]
22-
}
23-
}
15+
datb = sha512.Sum512(data)
2416

2517
baseSize := uint64(len(f))
2618
bitLimit := f[len(f)-1]
@@ -52,8 +44,8 @@ func get(f []byte, data []byte, anslen uint64) (ret []byte) {
5244

5345
// Process rounds
5446
outer:
55-
for roundx := uint32(0); roundx < ROUNDS; roundx++ {
56-
for roundy := roundx + 1; roundy < ROUNDS; roundy++ {
47+
for roundx := uint32(1); roundx < ROUNDS; roundx++ {
48+
for roundy := uint32(0); roundy < roundx; roundy++ {
5749
var allDone uint64
5850
for i := range done {
5951
for j := 0; j < 8; j++ {

v1/store.go

Lines changed: 13 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,7 @@ func store(fs []byte, data []byte, answer []byte, bitLimit byte) uint64 {
1414
}
1515

1616
var datb [64]byte
17-
if len(data) > 63 {
18-
datb = sha512.Sum512(data)
19-
} else {
20-
copy(datb[:], data)
21-
datb[63] = byte(len(data))
22-
for i := range datb {
23-
datb[(i+1)&63] ^= datb[i]
24-
}
25-
}
17+
datb = sha512.Sum512(data)
2618

2719
baseSize := uint64(len(fs))
2820
cells := cellSize(baseSize - 1)
@@ -42,14 +34,14 @@ func store(fs []byte, data []byte, answer []byte, bitLimit byte) uint64 {
4234

4335
// Track active filters and their insertion counts
4436
active := make([]bool, storedBits, storedBits)
37+
mutated := make([]bool, storedBits, storedBits)
4538

46-
var totalInserted uint64
4739
//println(storedBits, cells, baseSize)
4840

4941
// Process rounds
5042
outer:
51-
for roundx := uint32(0); roundx < ROUNDS; roundx++ {
52-
for roundy := roundx + 1; roundy < ROUNDS; roundy++ {
43+
for roundx := uint32(1); roundx < ROUNDS; roundx++ {
44+
for roundy := uint32(0); roundy < roundx; roundy++ {
5345
anyActive := false
5446
x := binary.BigEndian.Uint32(datb[4*roundx:])
5547
y := binary.BigEndian.Uint32(datb[4*roundy:])
@@ -75,22 +67,21 @@ outer:
7567
active[i] = true
7668
} else {
7769
fs[pos] |= (bit + 1) << shift
78-
totalInserted++
79-
active[i] = true
70+
mutated[i] = true
8071
}
8172
case 1:
8273
if bit == 0 {
8374
active[i] = true
8475
} else {
8576
fs[pos] |= 3 << shift
86-
totalInserted++
77+
mutated[i] = true
8778
}
8879
case 2:
8980
if bit == 1 {
9081
active[i] = true
9182
} else {
9283
fs[pos] |= 3 << shift
93-
totalInserted++
84+
mutated[i] = true
9485
}
9586
}
9687
}
@@ -100,7 +91,12 @@ outer:
10091
}
10192
}
10293
}
103-
94+
var totalInserted uint64
95+
for i := uint64(0); i < storedBits; i++ {
96+
if mutated[i] {
97+
totalInserted++
98+
}
99+
}
104100
// Finalize insertion counts
105101
return totalInserted
106102
}

0 commit comments

Comments
 (0)