u32

package
v0.0.0-...-0597d20 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 22, 2018 License: MIT Imports: 5 Imported by: 0

README

u32

uint32 utils

Documentation

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func Decode

func Decode(bytes []byte) uint32

Decode is bytes to uint32.

func Encode

func Encode(num uint32) []byte

Encode is uint32 to bytes.

func IsIntersect

func IsIntersect(a, b []uint32) bool

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

func Jaccard(a, b []uint32) int

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

func StrToUint32(str string) uint32

StrToUint32 string to uint32.

Example
fmt.Println(StrToUint32("4dItAQ"))
fmt.Println(StrToUint32("end"))
Output:

19780321
30586

func Uint32ToStr

func Uint32ToStr(num uint32) string

Uint32ToStr uint32 to string.

Example
fmt.Println(Uint32ToStr(19780321))
fmt.Println(Uint32ToStr(30586))
Output:

4dItAQ
enc

Types

type Count

type Count struct {
	Num uint32
	Sum uint8
}

Count is count Uint32.

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) Sort

func (p Int32Slice) Sort()

Sort []uint32.

func (Int32Slice) Swap

func (p Int32Slice) Swap(i, j int)

type Set

type Set map[uint32]bool

Set uint32集合.

func NewSet

func NewSet(nums ...uint32) *Set

NewSet 新建uint32集合.

Example
set := NewSet(1, 2, 3, 3, 2, 1)
fmt.Println(set.Numbers())
Output:

[1 2 3]

func (Set) Add

func (a Set) Add(nums ...uint32)

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) Complement

func (a *Set) Complement(full *Set)

Complement 补集.

func (*Set) Contain

func (a *Set) Contain(sets ...*Set) bool

Contain 全包含..

func (Set) Copy

func (a Set) Copy() Set

Copy 复制.

func (*Set) Empty

func (a *Set) Empty() bool

Empty 是否为空.

func (*Set) Equal

func (a *Set) Equal(b *Set) bool

Equal 集合比较.

func (Set) Has

func (a Set) Has(nums ...uint32) bool

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

func (a Set) HasAll(nums ...uint32) bool

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

func (a Set) Hit(nums ...uint32) int

Hit 命中次数.

Example
set := NewSet(1, 2, 3)
fmt.Println(set.Hit(2, 3, 4, 5))
Output:

2

func (Set) Intersect

func (a Set) Intersect(sets ...*Set)

Intersect 交集.

func (*Set) Jaccard

func (a *Set) Jaccard(sets ...*Set) int

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

func (*Set) Len

func (a *Set) Len() int

Len 长度.

Example
set := NewSet(1, 2, 3, 3)
fmt.Println(set.Len())
Output:

3

func (Set) Minus

func (a Set) Minus(sets ...*Set)

Minus 减去.

func (Set) Numbers

func (a Set) Numbers() []uint32

Numbers 返回[]uint32.

func (Set) Remove

func (a Set) Remove(nums ...uint32) *Set

Remove 删除.

func (Set) Retain

func (a Set) Retain(nums ...uint32)

Retain 交集.

func (Set) Union

func (a Set) Union(sets ...*Set)

Union 并集.

type SetCount

type SetCount map[uint32]*Count

SetCount set count.

func (SetCount) Add

func (m SetCount) Add(sets ...*Set)

Add is SetCount add Sets.

func (SetCount) Count

func (m SetCount) Count(removeSets ...*Set) []Count

Count is SetCount count.

Example
sc := SetCount{}
sc.Add(NewSet(1, 2, 3))
sc.Add(NewSet(2, 3, 4), NewSet(4, 5, 6))
fmt.Println(len(sc))
fmt.Println(sc.Count())
Output:

6
[{2 2} {3 2} {4 2} {1 1} {5 1} {6 1}]

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL