Skip to content

Commit bc9600a

Browse files
committed
De-tupleize the Components() return value.
1 parent b12d7ca commit bc9600a

File tree

1 file changed

+30
-18
lines changed

1 file changed

+30
-18
lines changed

ProbabilisticDataStructures/CuckooBloomFilter.cs

Lines changed: 30 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -121,10 +121,10 @@ public uint Count()
121121
/// <returns>Whether or not the data is a member</returns>
122122
public bool Test(byte[] data)
123123
{
124-
var components = this.Components(data);
125-
var i1 = components.Item1;
126-
var i2 = components.Item2;
127-
var f = components.Item3;
124+
var components = this.GetComponents(data);
125+
var i1 = components.Hash1;
126+
var i2 = components.Hash2;
127+
var f = components.Fingerprint;
128128

129129
// If either bucket containsf, it's a member.
130130
var b1 = this.Buckets[i1 % this.M];
@@ -156,10 +156,10 @@ public bool Test(byte[] data)
156156
/// </returns>
157157
public bool Add(byte[] data)
158158
{
159-
var components = this.Components(data);
160-
var i1 = components.Item1;
161-
var i2 = components.Item2;
162-
var f = components.Item3;
159+
var components = this.GetComponents(data);
160+
var i1 = components.Hash1;
161+
var i2 = components.Hash2;
162+
var f = components.Fingerprint;
163163
return this.Insert(i1, i2, f);
164164
}
165165

@@ -175,10 +175,10 @@ public bool Add(byte[] data)
175175
/// </returns>
176176
public Tuple<bool, bool> TestAndAdd(byte[] data)
177177
{
178-
var components = this.Components(data);
179-
var i1 = components.Item1;
180-
var i2 = components.Item2;
181-
var f = components.Item3;
178+
var components = this.GetComponents(data);
179+
var i1 = components.Hash1;
180+
var i2 = components.Hash2;
181+
var f = components.Fingerprint;
182182

183183
// If either bucket contains f, it's a member.
184184
var b1 = this.Buckets[i1 % this.M];
@@ -207,10 +207,10 @@ public Tuple<bool, bool> TestAndAdd(byte[] data)
207207
/// <returns>Whether the data was a member or not</returns>
208208
public bool TestAndRemove(byte[] data)
209209
{
210-
var components = this.Components(data);
211-
var i1 = components.Item1;
212-
var i2 = components.Item2;
213-
var f = components.Item3;
210+
var components = this.GetComponents(data);
211+
var i1 = components.Hash1;
212+
var i2 = components.Hash2;
213+
var f = components.Fingerprint;
214214

215215
// Try to remove from bucket[i1].
216216
var b1 = this.Buckets[i1 % this.M];
@@ -377,14 +377,19 @@ private bool Insert(uint i1, uint i2, byte[] f)
377377
/// <param name="data">Data</param>
378378
/// <returns>The two hash values used to index into the buckets and the
379379
/// fingerprint for the given data</returns>
380-
private Tuple<uint, uint, byte[]> Components(byte[] data)
380+
private Components GetComponents(byte[] data)
381381
{
382382
var hash = this.ComputeHash(data);
383383
var f = hash.Take((int)this.F).ToArray();
384384
var i1 = ProbabilisticDataStructures.ToBigEndianUInt32(hash);
385385
var i2 = ProbabilisticDataStructures.ToBigEndianUInt32(this.ComputeHash(f));
386386

387-
return Tuple.Create<uint, uint, byte[]>(i1, i2, f);
387+
return new Components
388+
{
389+
Fingerprint = f,
390+
Hash1 = i1,
391+
Hash2 = i2
392+
};
388393
}
389394

390395
/// <summary>
@@ -435,5 +440,12 @@ private static uint Power2(uint x)
435440
x++;
436441
return x;
437442
}
443+
444+
private struct Components
445+
{
446+
public byte[] Fingerprint;
447+
public uint Hash1;
448+
public uint Hash2;
449+
}
438450
}
439451
}

0 commit comments

Comments
 (0)