xdb

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Apr 10, 2026 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

View Source
const (
	Structure20      = 2
	Structure30      = 3
	HeaderInfoLength = 256
	VectorIndexRows  = 256
	VectorIndexCols  = 256
	VectorIndexSize  = 8
)
View Source
const (
	IPv4VersionNo = 4
	IPv6VersionNo = 6
)

Variables

View Source
var (
	IPvx = &Version{}
	IPv4 = &Version{
		Id:               IPv4VersionNo,
		Name:             "IPv4",
		Bytes:            4,
		SegmentIndexSize: 14,
		IPCompare: func(ip1, ip2 []byte) int {

			ip2[0], ip2[3] = ip2[3], ip2[0]
			ip2[1], ip2[2] = ip2[2], ip2[1]
			return bytes.Compare(ip1, ip2)
		},
	}
	IPv6 = &Version{
		Id:               IPv6VersionNo,
		Name:             "IPv6",
		Bytes:            16,
		SegmentIndexSize: 38,
		IPCompare: func(ip1, ip2 []byte) int {
			return bytes.Compare(ip1, ip2)
		},
	}
)

Functions

func IP2String

func IP2String(ip []byte) string

func IPAddOne

func IPAddOne(ip []byte) []byte

func IPCompare

func IPCompare(ip1, ip2 []byte) int

IPCompare compares two IP addresses Returns: -1 if ip1 < ip2, 0 if ip1 == ip2, 1 if ip1 > ip2

func IPSubOne

func IPSubOne(ip []byte) []byte

func LoadVectorIndexFromBuff

func LoadVectorIndexFromBuff(cBuff []byte) ([]byte, error)

func ParseIP

func ParseIP(ip string) ([]byte, error)

Types

type Header struct {
	// data []byte
	Version       uint16
	IndexPolicy   IndexPolicy
	CreatedAt     uint32
	StartIndexPtr uint32
	EndIndexPtr   uint32

	// since IPv6 supporting
	IPVersion       int
	RuntimePtrBytes int
}

func LoadHeaderFromBuff

func LoadHeaderFromBuff(cBuff []byte) (*Header, error)

LoadHeaderFromBuff wrap the header info from the content buffer

func NewHeader

func NewHeader(input []byte) (*Header, error)

func (*Header) String

func (h *Header) String() string

type IndexPolicy

type IndexPolicy int
const (
	VectorIndexPolicy IndexPolicy = 1
	BTreeIndexPolicy  IndexPolicy = 2
)

func (IndexPolicy) String

func (i IndexPolicy) String() string

type Searcher

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

func NewSearcher

func NewSearcher(version *Version, vIndex []byte, cBuff []byte) (*Searcher, error)

func NewWithBuffer

func NewWithBuffer(version *Version, cBuff []byte) (*Searcher, error)

func (*Searcher) Close

func (s *Searcher) Close()

func (*Searcher) GetIOCount

func (s *Searcher) GetIOCount() int

GetIOCount return the global io count for the last search

func (*Searcher) IPVersion

func (s *Searcher) IPVersion() *Version

IPVersion return the ip version

func (*Searcher) Search

func (s *Searcher) Search(ip []byte) (string, error)

Search find the region for the specified long ip

func (*Searcher) SearchByStr

func (s *Searcher) SearchByStr(str string) (string, error)

SearchByStr find the region for the specified ip string

type Version

type Version struct {
	Id               int
	Name             string
	Bytes            int
	SegmentIndexSize int

	// function to compare two ips
	IPCompare func([]byte, []byte) int
}

func VersionFromHeader

func VersionFromHeader(header *Header) (*Version, error)

func VersionFromIP

func VersionFromIP(ip string) (*Version, error)

func VersionFromName

func VersionFromName(name string) (*Version, error)

func (*Version) String

func (v *Version) String() string

Jump to

Keyboard shortcuts

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