Documentation ¶
Index ¶
- Constants
- Variables
- type Bloom
- func (b Bloom) Big() *big.Int
- func (b Bloom) BloomRLP() *BloomRLP
- func (b *Bloom) DecodeRLP(s *rlp.Stream) error
- func (b *Bloom) Digest(k []byte) *Bloom
- func (b *Bloom) EncodeRLP(w io.Writer) error
- func (b Bloom) Hex() string
- func (b Bloom) IsEqual(B *Bloom) bool
- func (b *Bloom) LookAt(idx uint32) bool
- func (b Bloom) LookUp(k []byte) bool
- func (b *Bloom) Or(x, y *Bloom) *Bloom
- func (b *Bloom) SetAt(idx uint32)
- func (b *Bloom) SetBytes(d []byte)
- type BloomConfig
- type BloomRLP
- type Bucket
- type BucketConfig
- type BucketRLP
- type Data
- type DataHash
- func (d DataHash) Big() *big.Int
- func (d DataHash) Bytes() []byte
- func (d DataHash) Hex() string
- func (d DataHash) IsEmpty() bool
- func (d DataHash) IsEqual(K DataHash) bool
- func (d DataHash) Less(comp DataHash) bool
- func (d DataHash) Lsb() bool
- func (d DataHash) Lsh(n int) DataHash
- func (d DataHash) SetBytes(b []byte)
- func (d DataHash) Xor(a, b DataHash) DataHash
- type EstimatorConfig
- type Graphene
- func (g Graphene) Bloom() *Bloom
- func (g Graphene) BloomConfig() BloomConfig
- func (g *Graphene) DecodeRLP(s *rlp.Stream) error
- func (g *Graphene) EncodeRLP(w io.Writer) error
- func (g Graphene) Filter(bob map[common.Hash]Data)
- func (g *Graphene) FilterDecode(bob map[common.Hash]Data) map[common.Hash]Data
- func (g *Graphene) FilterListRLP(i interface{}) (Alice [][]byte, err error)
- func (g Graphene) FilterRLP(i interface{}) map[interface{}]interface{}
- func (g *Graphene) Insert(x Data)
- func (g *Graphene) InsertMap(m map[common.Hash]Data) *Graphene
- func (g *Graphene) InsertRLP(k, v interface{})
- func (g Graphene) InvBloom() *InvBloom
- func (g Graphene) InvBloomConfig() InvBloomConfig
- func (g Graphene) ListRLP() (Alice, Bob [][]byte, err error)
- func (g Graphene) LookUp(x Data) bool
- func (g *Graphene) Recover(i interface{}) (alice [][]byte, err error)
- type GrapheneRLP
- type HashPool
- func (p HashPool) Comp(pp *HashPool) int
- func (p HashPool) Decode(pp *HashPool) uint
- func (p *HashPool) DecodeRLP(s *rlp.Stream) error
- func (p *HashPool) Encode(d Data)
- func (p *HashPool) EncodeRLP(w io.Writer) error
- func (p HashPool) GetK() int
- func (p HashPool) MinHash(k uint) SortDataHash
- func (p *HashPool) String() string
- type HashPoolConfig
- type HashPoolRLP
- type HybridEstimator
- func (e *HybridEstimator) Config() HybridEstimatorConfig
- func (e *HybridEstimator) Decode(r *HybridEstimator) uint
- func (e *HybridEstimator) DecodeRLP(s *rlp.Stream) error
- func (e HybridEstimator) DeriveConfig(r *HybridEstimator) InvBloomConfig
- func (e *HybridEstimator) Encode(d Data)
- func (e *HybridEstimator) EncodeByte(b []byte)
- func (e *HybridEstimator) EncodeRLP(w io.Writer) error
- func (e HybridEstimator) NewData() Data
- func (e HybridEstimator) NewDataHash() DataHash
- func (e *HybridEstimator) String() string
- type HybridEstimatorConfig
- type HybridEstimatorRLP
- type IBloomStrataRLP
- type InvBloom
- func (b InvBloom) Config() InvBloomConfig
- func (b *InvBloom) Decode(alice, bob map[common.Hash]Data) bool
- func (b *InvBloom) DecodeRLP(s *rlp.Stream) error
- func (b *InvBloom) Delete(k Data) bool
- func (b *InvBloom) EncodeRLP(w io.Writer) error
- func (b *InvBloom) Insert(x Data)
- func (b *InvBloom) InsertMap(m map[common.Hash]Data) *InvBloom
- func (b *InvBloom) InsertRLP(k, v interface{})
- func (b *InvBloom) ListRLP() (Alice, Bob [][]byte, err error)
- func (b *InvBloom) NewBucket() *Bucket
- func (b InvBloom) NewData() Data
- func (b InvBloom) String() string
- func (z *InvBloom) Subtract(a, b *InvBloom) *InvBloom
- type InvBloomConfig
- type InvBloomRLP
- type MapWork
- type Operation
- type SortData
- type SortDataHash
- type StrataEstimator
- func (e *StrataEstimator) DecodeData(r *StrataEstimator) uint
- func (e *StrataEstimator) DecodeRLP(s *rlp.Stream) error
- func (e *StrataEstimator) EncodeData(d Data)
- func (e *StrataEstimator) EncodeRLP(w io.Writer) error
- func (e StrataEstimator) NewDataHash() DataHash
- func (e StrataEstimator) String() string
- func (e StrataEstimator) TrailingZeros(h DataHash) uint
- type StrataEstimatorRLP
- type WorkReq
- type WorkResp
Constants ¶
const ( // BucketNum represents the number of total buckets BucketNumBits = 12 BucketNum = 1 << BucketNumBits // BucketKeyHashLength is the number of bytes taken from // the hash of inserted RLP key BucketKeyHashLength = 6 // BucketSerNumLength is the number of bytes used as index // if modified, change uint16 to corresponding types BucketSerNumLength = 2 // BucketKeyLength represents the length of bytes used by keys BucketKeyLength = BucketKeyHashLength + BucketSerNumLength // BucketValueLength represents the length fo bytes used by keys BucketValueLength = 8 DataLength = BucketKeyLength + BucketValueLength // Number of used buckets in BucketNum of buckets BucketUsed = 4 // Number of byte used in key hash KeyHashLength = 4 // BloomBitLength is the number of bits in a classical bloom filter BloomLengthBits = 18 BloomBitLength = 1 << BloomLengthBits // BloomByteLength is the number of bytes in a classical bloom filter BloomByteLength = BloomBitLength / 8 // number of bits per Digest-ed element BloomUsedBits = 7 )
Constants left here for reference
Variables ¶
var ( ErrNoOpFunc = errors.New("not set operated function") ErrNoData = errors.New("not provide data") )
var ( ErrKeyDuplicate = errors.New("insert key duplicated") ErrPtrEmpty = errors.New("input nil pointer") ErrDecodeFailed = errors.New("decode IBLT failed") )
Errors
var (
WorkMap = InitWorkMap(runtime.NumCPU())
)
Functions ¶
This section is empty.
Types ¶
type Bloom ¶
type Bloom struct {
// contains filtered or unexported fields
}
Struct of bloom comprises a bloom of byte slice and a config
func NewBloom ¶
func NewBloom(config BloomConfig) *Bloom
func (*Bloom) Digest ¶
For certain value k, execute the required hashes, and set the value of the corresponding bloom bit to 1
func (Bloom) IsEqual ¶
IsEqual tests whether the caller Bloom object is identical to the parameter B.
type BloomConfig ¶
type BloomConfig struct { // Length of bloom on byte (not en bit) BloomByteLength uint // Number of Hash functions BloomBits uint }
Configuration of bloom
func DeriveBloomConfig ¶
func DeriveBloomConfig(count int) BloomConfig
Proposed config of Bloom according to the paper given the number of elements.
func NewBloomConfig ¶
func NewBloomConfig(len, bits uint) BloomConfig
Create a new BloomConfig where the input len is the log2 of the length of bloom on bit
type BloomRLP ¶
type BloomRLP struct { Bloom []byte Config BloomConfig }
The struct(s) end with -RLP are what actually transmitting on the networks. The conversion from original bloom to -RLP bloom is implemented, they are used in EncodeRLP and DecodeRLP functions which implicitly implements RLP encoder.
type Bucket ¶
IBLT are made of buckets. The construction of bucket is slightly different from what the paper says, as there is no key here.
func NewBucket ¶
func NewBucket(config BucketConfig) (b *Bucket)
Create a new bucket according to its configuraion.
type BucketConfig ¶
type BucketConfig struct { //length of data by bytes DataLen uint //length of hash by bytes HashLen uint }
Configuration of bucket in IBLT.
func NewBucketConfig ¶
func NewBucketConfig(dataLen, hashLen uint) BucketConfig
Create a new bucket configuration
func (BucketConfig) String ¶
func (config BucketConfig) String() string
type Data ¶
type Data []byte
Defined data types used in IBLT
type DataHash ¶
type DataHash []byte
func NewDataHash ¶
type EstimatorConfig ¶
type EstimatorConfig struct { // number of layers of strata StrataNum uint // Configuration of IBLT for each layer IBLTConfig InvBloomConfig }
func NewEstimatorConfig ¶
func NewEstimatorConfig(n uint) EstimatorConfig
Create a new estimator config according to the default setting of IBLT
func (EstimatorConfig) String ¶
func (config EstimatorConfig) String() string
type Graphene ¶
type Graphene struct {
// contains filtered or unexported fields
}
Graphene are made of a bloom and an invBloom
func NewGraphene ¶
func NewGraphene(i InvBloomConfig, b BloomConfig) *Graphene
Create a new Graphene with the configurations of bloom and invBloom.
func (Graphene) BloomConfig ¶
func (g Graphene) BloomConfig() BloomConfig
Return the config of the Bloom in the Graphene
func (Graphene) Filter ¶
Filter filters out the keys in bob that are impossible in Alice by the filtering of bloom in Graphene. Remember there is still false positive.
func (*Graphene) FilterDecode ¶
FilterDecode returns the unique elements of Alice not existing in Bob. It modified the callee.
func (*Graphene) FilterListRLP ¶
FilterListRLP returns the slice of RLP coded slices that are uniquely in caller's bloom lookup table.
func (Graphene) FilterRLP ¶
func (g Graphene) FilterRLP(i interface{}) map[interface{}]interface{}
FilterRLP filters out the keys that are impossible in the map's keys it will not modify the input interface. it panics if the input is not an valid map.
func (*Graphene) Insert ¶
Insert inserts the key-value pair into certain bucket in the bloom. This operation always succeeds, assuming that all keys are distinct.
func (*Graphene) InsertRLP ¶
func (g *Graphene) InsertRLP(k, v interface{})
call the InsertRLP method of invBloom
func (Graphene) InvBloomConfig ¶
func (g Graphene) InvBloomConfig() InvBloomConfig
Return the config of the IBLT in the Graphene
type GrapheneRLP ¶
type GrapheneRLP struct { Bloom *BloomRLP InvBloom *InvBloomRLP }
type HashPool ¶
type HashPool struct {
// contains filtered or unexported fields
}
HashPool stores sorted hashes, the first K hashes will be selected for comparison in order to estimate the set difference
func (HashPool) MinHash ¶
func (p HashPool) MinHash(k uint) SortDataHash
MinHash chooses and returns K smallest hashes
type HashPoolConfig ¶
type HashPoolConfig struct { // length of Hash by bytes HashLen uint // K is the number of elements with smallest hash values // chosen for the estimation of difference K uint }
The configuration of HashPool
type HashPoolRLP ¶
type HashPoolRLP struct { Hashes SortDataHash Config HashPoolConfig }
type HybridEstimator ¶
type HybridEstimator struct {
// contains filtered or unexported fields
}
HybridEstimator combines strata estimator and min-hash estimator to estimate the set difference between two parties.
func NewHybridEstimator ¶
func NewHybridEstimator(config HybridEstimatorConfig) *HybridEstimator
Create a new hybrid estimator using the hybridEstimator config
func (*HybridEstimator) Config ¶
func (e *HybridEstimator) Config() HybridEstimatorConfig
Return the configuration of the two estimators
func (*HybridEstimator) Decode ¶
func (e *HybridEstimator) Decode(r *HybridEstimator) uint
Calculate the difference of the two hybridEstimators
func (HybridEstimator) DeriveConfig ¶
func (e HybridEstimator) DeriveConfig(r *HybridEstimator) InvBloomConfig
According to the estimator of the sender, the receiver determines the configuration of the IBLT used for later transmission
func (*HybridEstimator) Encode ¶
func (e *HybridEstimator) Encode(d Data)
Put a data in the hybridEstimator Whether we should deal with it by strata or by minHash depends on its number of layer
func (*HybridEstimator) EncodeByte ¶
func (e *HybridEstimator) EncodeByte(b []byte)
Equivalent to Encode
func (HybridEstimator) NewData ¶
func (e HybridEstimator) NewData() Data
Create a new byte slice with length equal to the length of data
func (HybridEstimator) NewDataHash ¶
func (e HybridEstimator) NewDataHash() DataHash
func (*HybridEstimator) String ¶
func (e *HybridEstimator) String() string
type HybridEstimatorConfig ¶
type HybridEstimatorConfig struct { StrataConfig EstimatorConfig MinWiseConfig HashPoolConfig }
The configuration of both the Strata Estimator and the HashPool
func NewHybridEstimatorConfig ¶
func NewHybridEstimatorConfig() HybridEstimatorConfig
Create a new hybrid estimatorConfig with the suggested configuration
type HybridEstimatorRLP ¶
type HybridEstimatorRLP struct { Strata *StrataEstimatorRLP MinWise *HashPoolRLP Config HybridEstimatorConfig }
type IBloomStrataRLP ¶
This is different from InvBloomRLP, we have to drop the config field since it's unnecessary to carry the same config for different strata. They are saved under strata's config field.
type InvBloom ¶
type InvBloom struct {
// contains filtered or unexported fields
}
The structure of IBLT
func (*InvBloom) Decode ¶
Decode should be called after InvBloom subtraction alice stores the KV pairs that b, the caller has, bob stores the KV pairs that b, the caller has not.
Example: A: {"foo":"a1", "bar":"a2", "foo1":"common1", "bar1":"common2"} B: {"baz":"b1", "qux":"b2", "foo1":"common1", "bar1":"common2"}
C := A - B
C.Decode(alice, bob)
alice: {"foo":"a1", "bar":"a2"} bob: {"baz":"b1", "qux":"b2"}
Their common KV pairs are canceled, only when it returns true could their distinct pairs be Decode-ed. If it returns false, the partial pairs are not guaranteed to be correct.
Attention: Decode modifies the callee object. If one needs a non-corrupted version of decode, call Decode by a copy of that. TODO, optimize to use queue
func (*InvBloom) InsertRLP ¶
func (b *InvBloom) InsertRLP(k, v interface{})
InsertRLP inserts any k, v to IBLT using RLP coding it prints error if input is invalid or encode throws error
func (*InvBloom) ListRLP ¶
b is already the subtraction of two IBLTs, if the decode succeeds, reconstruct the two original sets
type InvBloomConfig ¶
type InvBloomConfig struct { // The configuration of buckets of IBLT BktConfig BucketConfig // BucketNum represents the number of total buckets BucketNum uint // Number of used buckets in BucketNum of buckets BucketUsed uint // Number of bytes reserved to record the key KeyLen uint // Number of bytes reserved to record the value ValLen uint // Number of bytes reserved to record the section number SerNumLen uint }
Configuration of IBLT
func NewInvBloomConfig ¶
func NewInvBloomConfig(bkt uint, used uint) InvBloomConfig
Create a new InvBloom Config according two the config of buckets in the context of transmission of transactions
func (InvBloomConfig) String ¶
func (config InvBloomConfig) String() string
type InvBloomRLP ¶
type InvBloomRLP struct { Buckets []*BucketRLP Config InvBloomConfig Salt uint8 }
type MapWork ¶
type MapWork struct {
// contains filtered or unexported fields
}
func InitWorkMap ¶
func (*MapWork) AbortWorks ¶
func (work *MapWork) AbortWorks()
func (*MapWork) SetOperation ¶
func (*MapWork) StartWorks ¶
type SortDataHash ¶
type SortDataHash []DataHash
func (SortDataHash) Len ¶
func (k SortDataHash) Len() int
func (SortDataHash) Less ¶
func (k SortDataHash) Less(i, j int) bool
func (SortDataHash) Swap ¶
func (k SortDataHash) Swap(i, j int)
type StrataEstimator ¶
type StrataEstimator struct {
// contains filtered or unexported fields
}
StrataEstimator is a strata estimator consists of an array of IBLT, each element is inserted to an IBLT corresponding to its level of key
func NewEstimator ¶
func NewEstimator(config EstimatorConfig) *StrataEstimator
Create a new estimator according to estimatorConfig
func (*StrataEstimator) DecodeData ¶
func (e *StrataEstimator) DecodeData(r *StrataEstimator) uint
Calculate the difference of two StrataEstimator
func (*StrataEstimator) EncodeData ¶
func (e *StrataEstimator) EncodeData(d Data)
Add a new data into the strata estimator
func (StrataEstimator) NewDataHash ¶
func (e StrataEstimator) NewDataHash() DataHash
Create an empty byte slice with the setting of hash length
func (StrataEstimator) String ¶
func (e StrataEstimator) String() string
func (StrataEstimator) TrailingZeros ¶
func (e StrataEstimator) TrailingZeros(h DataHash) uint
Determine the layer of IBLT the data should be inserted into by calculating the number of preceding zeros
type StrataEstimatorRLP ¶
type StrataEstimatorRLP struct { Count uint Strata []*IBloomStrataRLP Config EstimatorConfig }