storage

package
v0.0.0-...-91e790a Latest Latest
Warning

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

Go to latest
Published: Oct 22, 2022 License: MIT Imports: 2 Imported by: 0

README

一些常用的存储结构

  • bitmap 并发安全的bitmap
  • NewBitMap(size uint64, lock_granularity uint64) *BitMap

    返回一个容量为size的bitmap,lock_granularity的意义为多少个bit共用一把锁。lock_granularity为0表示不加锁,即非线程安全的位图。

  • (b *BitMap) Get(pos uint64) bool 获取pos位置的值
  • (b *BitMap) Set(pos uint64, value bool) 设置pos位置的值
package main

import (
	"fmt"

	"github.com/ACV-er/gotools/storage"
)

func main() {
	bm := storage.NewBitMap(10000, 1000)
	bm.Set(15, true)
	bm.Set(50, true)

	// 15 true 16 false
	fmt.Printf("15 %#v 16 %#v\n", bm.Get(15), bm.Get(16))
	bm.Set(50, false)

	// 50 false
	fmt.Printf("50 %#v\n", bm.Get(50))
}

Documentation

Index

Constants

View Source
const (
	MAX_LEVEL = 32
	P_FACTOR  = 0.25
)

Variables

This section is empty.

Functions

This section is empty.

Types

type BitMap

type BitMap interface {
	Get(uint64) bool
	Set(uint64, bool)
}

func NewBitMap

func NewBitMap(size uint64, lock_granularity uint64) BitMap

type CmpReq

type CmpReq int
const (
	LE CmpReq = iota
	EQ CmpReq = iota
	GT CmpReq = iota
)

type Interface

type Interface interface {
	Cmp(interface{}) CmpReq
}

type Node

type Node struct {
	// contains filtered or unexported fields
}

func (*Node) Load

func (n *Node) Load() Interface

func (*Node) Next

func (n *Node) Next() *Node

func (*Node) Pre

func (n *Node) Pre() *Node

type Queue

type Queue interface {
	Push(interface{})
	Pop() interface{}
	Front() interface{}
	Back() interface{}
	Size() int
	Clean()
}

func NewListQueue

func NewListQueue() Queue

type Skiplist

type Skiplist struct {
	// contains filtered or unexported fields
}

func NewSkipList

func NewSkipList() Skiplist

func (*Skiplist) Add

func (s *Skiplist) Add(val Interface)

func (*Skiplist) Erase

func (s *Skiplist) Erase(val Interface) bool

func (*Skiplist) Front

func (s *Skiplist) Front() *Node

func (*Skiplist) Search

func (s *Skiplist) Search(target Interface) bool

Jump to

Keyboard shortcuts

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