@cryptotaxi247 / kubo / commits / c7e3d5d2a

add comment detailing the algorithm and fix

License: MIT Signed-off-by: Jeromy <why@ipfs.io>

Jeromy committed Sep 29, 2016 at 13:19 UTC c7e3d5d2ac951ae09e341546a6244033eab58722
1 file changed +13
pin/set.go
+13
@@ -139,6 +139,19 @@ func storeItems(ctx context.Context, dag merkledag.DAGService, estimatedLen uint
139 }
140 hashed := make(map[uint32][]item)
141 for {
142 + // This loop essentially enumerates every single item in the set
143 + // and maps them all into a set of buckets. Each bucket will be recursively
144 + // turned into its own sub-set, and so on down the chain. Each sub-set
145 + // gets added to the dagservice, and put into its place in a set nodes
146 + // links array.
147 + //
148 + // Previously, the bucket was selected by taking an int32 from the hash of
149 + // the input key + seed. This was erroneous as we would later be assigning
150 + // the created sub-sets into an array of length 256 by the modulus of the
151 + // int32 hash value with 256. This resulted in overwriting existing sub-sets
152 + // and losing pins. The fix (a few lines down from this comment), is to
153 + // map the hash value down to the 8 bit keyspace here while creating the
154 + // buckets. This way, we avoid any overlapping later on.
155 k, data, ok := iter()
156 if !ok {
157 break