Documentation ¶
Index ¶
- func Decode(bytes []byte) uint32
- func Encode(num uint32) []byte
- func IsIntersect(a, b []uint32) bool
- func Jaccard(a, b []uint32) int
- func StrToUint32(str string) uint32
- func Uint32ToStr(num uint32) string
- type Count
- type Int32Slice
- type Set
- func (a Set) Add(nums ...uint32)
- func (a *Set) Clear()
- func (a *Set) Complement(full *Set)
- func (a *Set) Contain(sets ...*Set) bool
- func (a Set) Copy() Set
- func (a *Set) Empty() bool
- func (a *Set) Equal(b *Set) bool
- func (a Set) Has(nums ...uint32) bool
- func (a Set) HasAll(nums ...uint32) bool
- func (a Set) Hit(nums ...uint32) int
- func (a Set) Intersect(sets ...*Set)
- func (a *Set) Jaccard(sets ...*Set) int
- func (a *Set) Len() int
- func (a Set) Minus(sets ...*Set)
- func (a Set) Numbers() []uint32
- func (a Set) Remove(nums ...uint32) *Set
- func (a Set) Retain(nums ...uint32)
- func (a Set) Union(sets ...*Set)
- type SetCount
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func IsIntersect ¶
IsIntersect A and B is sorted
Example ¶
fmt.Println(IsIntersect([]uint32{}, []uint32{3, 4, 5})) fmt.Println(IsIntersect([]uint32{1, 2, 3}, []uint32{3, 4, 5})) fmt.Println(IsIntersect([]uint32{1, 2, 6}, []uint32{3, 4, 5}))
Output: false true false
func Jaccard ¶
Jaccard (A, B) = |A intersect B| / |A union B| * 1000
Example ¶
fmt.Println(Jaccard([]uint32{1, 2, 3}, []uint32{1, 2, 4})) fmt.Println(Jaccard([]uint32{1, 2, 3}, []uint32{1, 4, 5})) fmt.Println(Jaccard([]uint32{1, 2, 3}, []uint32{1, 4, 5, 6, 7, 8}))
Output: 500 200 125
func StrToUint32 ¶
StrToUint32 string to uint32.
Example ¶
fmt.Println(StrToUint32("4dItAQ")) fmt.Println(StrToUint32("end"))
Output: 19780321 30586
func Uint32ToStr ¶
Uint32ToStr uint32 to string.
Example ¶
fmt.Println(Uint32ToStr(19780321)) fmt.Println(Uint32ToStr(30586))
Output: 4dItAQ enc
Types ¶
type Int32Slice ¶
type Int32Slice []uint32
Int32Slice is utin32 sort slice.
func (Int32Slice) Len ¶
func (p Int32Slice) Len() int
func (Int32Slice) Less ¶
func (p Int32Slice) Less(i, j int) bool
func (Int32Slice) Swap ¶
func (p Int32Slice) Swap(i, j int)
type Set ¶
Set uint32集合.
func NewSet ¶
NewSet 新建uint32集合.
Example ¶
set := NewSet(1, 2, 3, 3, 2, 1) fmt.Println(set.Numbers())
Output: [1 2 3]
func (Set) Add ¶
Add 增加uint32.
Example ¶
set := NewSet(1, 2) set.Add(4) set.Add(3, 2, 1, 4) fmt.Println(set.Numbers())
Output: [1 2 3 4]
func (*Set) Clear ¶
func (a *Set) Clear()
Clear 清空集合.
Example ¶
set := NewSet(1, 2, 3) fmt.Println(set.Numbers()) set.Clear() fmt.Println(set.Numbers())
Output: [1 2 3] []
func (Set) Has ¶
Has 是否包含任意一个uint32..
Example ¶
set := NewSet(6, 3) fmt.Println(set.Has(3)) fmt.Println(set.Has(6)) fmt.Println(set.Has(5)) fmt.Println(set.Has(3, 6)) fmt.Println(set.Has(3, 6, 5))
Output: true true false true true
func (Set) HasAll ¶
HasAll 是否包含全部uint32.
Example ¶
set := NewSet(6, 3) fmt.Println(set.HasAll(3)) fmt.Println(set.HasAll(6)) fmt.Println(set.HasAll(5)) fmt.Println(set.HasAll(3, 6)) fmt.Println(set.HasAll(3, 6, 5))
Output: true true false true false
func (Set) Hit ¶
Hit 命中次数.
Example ¶
set := NewSet(1, 2, 3) fmt.Println(set.Hit(2, 3, 4, 5))
Output: 2
func (*Set) Jaccard ¶
Jaccard 相似度 (A, B) = |A intersect B| / |A union B| * 1000
Example ¶
a := NewSet(1, 2, 3) b := NewSet(1, 2, 4) c := NewSet(1, 4, 5) d := NewSet(1, 4, 5, 6, 7, 8) fmt.Println(a.Jaccard(b)) fmt.Println(a.Jaccard(c)) fmt.Println(a.Jaccard(d))
Output: 500 200 125
Click to show internal directories.
Click to hide internal directories.