mirror of
https://github.com/tursom/GoCollections.git
synced 2026-08-22 07:03:28 +08:00
bloom support merge operation
This commit is contained in:
@@ -1,6 +1,5 @@
|
|||||||
package bloom
|
package bloom
|
||||||
|
|
||||||
import "C"
|
|
||||||
import (
|
import (
|
||||||
"encoding/binary"
|
"encoding/binary"
|
||||||
"io"
|
"io"
|
||||||
@@ -116,3 +115,15 @@ func Unmarshal(data []byte) *Bloom {
|
|||||||
c: uint(c),
|
c: uint(c),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (b *Bloom) Merge(bitMap []byte) bool {
|
||||||
|
if len(b.m) != len(bitMap) {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
for i := range b.m {
|
||||||
|
b.m[i] |= lang.UInt8(bitMap[i])
|
||||||
|
}
|
||||||
|
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|||||||
68
util/mr/utils.go
Normal file
68
util/mr/utils.go
Normal file
@@ -0,0 +1,68 @@
|
|||||||
|
package mr
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/tursom/GoCollections/collections"
|
||||||
|
"github.com/tursom/GoCollections/lang"
|
||||||
|
)
|
||||||
|
|
||||||
|
type MapEntry[K comparable, V any] struct {
|
||||||
|
key K
|
||||||
|
value V
|
||||||
|
}
|
||||||
|
|
||||||
|
func MapChannel[K comparable, V any](m map[K]V) lang.ReceiveChannel[*MapEntry[K, V]] {
|
||||||
|
ch := make(lang.RawChannel[*MapEntry[K, V]])
|
||||||
|
go func() {
|
||||||
|
for k, v := range m {
|
||||||
|
ch <- &MapEntry[K, V]{k, v}
|
||||||
|
}
|
||||||
|
|
||||||
|
close(ch)
|
||||||
|
}()
|
||||||
|
|
||||||
|
return ch
|
||||||
|
}
|
||||||
|
|
||||||
|
func ArrayChannel[E any](arr lang.Array[E]) lang.ReceiveChannel[E] {
|
||||||
|
ch := make(lang.RawChannel[E])
|
||||||
|
go func() {
|
||||||
|
for _, e := range arr {
|
||||||
|
ch <- e
|
||||||
|
}
|
||||||
|
|
||||||
|
close(ch)
|
||||||
|
}()
|
||||||
|
|
||||||
|
return ch
|
||||||
|
}
|
||||||
|
|
||||||
|
func SliceChannel[E any](arr []E) lang.ReceiveChannel[E] {
|
||||||
|
ch := make(lang.RawChannel[E])
|
||||||
|
go func() {
|
||||||
|
for _, e := range arr {
|
||||||
|
ch <- e
|
||||||
|
}
|
||||||
|
|
||||||
|
close(ch)
|
||||||
|
}()
|
||||||
|
|
||||||
|
return ch
|
||||||
|
}
|
||||||
|
|
||||||
|
func IteratorChannel[E any](iter collections.Iterator[E]) lang.ReceiveChannel[E] {
|
||||||
|
ch := make(lang.RawChannel[E])
|
||||||
|
go func() {
|
||||||
|
for iter.HasNext() {
|
||||||
|
next, e := iter.Next()
|
||||||
|
if e != nil {
|
||||||
|
panic(e)
|
||||||
|
}
|
||||||
|
|
||||||
|
ch <- next
|
||||||
|
}
|
||||||
|
|
||||||
|
close(ch)
|
||||||
|
}()
|
||||||
|
|
||||||
|
return ch
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user