structer

package module
v0.0.0-...-c1a4779 Latest Latest
Warning

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

Go to latest
Published: Oct 11, 2017 License: MIT Imports: 8 Imported by: 0

README

Structer

Storage for structures (embedded), with the ability to search by field structure. This library is unsafe.

API documentation Go Report Card

Usage

An example of using the Structer:

package main

import (
	"github.com/claygod/structer"
)

// Main
func main() {
	s := structer.New()
	...
}

Perfomance

  • Add-4 500000 4452 ns/op
  • AddParallel-4 500000 3104 ns/op
  • Find-4 2000000 909 ns/op
  • FindParallel-4 3000000 494 ns/op

API

Methods:

  • New - create a new storage for structures

Documentation

Index

Constants

View Source
const (
	ASC = iota
	DESC
)

Sorting the search result

View Source
const (
	RESERVED_SIZE_FOR_TAGS int = 10
	HOW_MANY_STRUCT_RETURN int = 20
)

Query defailt

View Source
const (
	TYPE_INT = iota
	TYPE_INT32
	TYPE_INT64
	TYPE_UINT
	TYPE_UINT32
	TYPE_UINT64
	TYPE_FLOAT32
	TYPE_FLOAT64
)

For spec

View Source
const RESERVED_SIZE_SLICE int = 100

RESERVED_SIZE_SLICE - default slice size

Variables

This section is empty.

Functions

This section is empty.

Types

type Blum

type Blum [65536]uint8

Blum - hashes

type Index

type Index struct {
	sync.Mutex
	// contains filtered or unexported fields
}

Index - string keys and number structures in the database

type Mark

type Mark struct {
	sync.Mutex
	// contains filtered or unexported fields
}

Mark - Repository of sub-tags (sections) Хранит массив id и списки по ключам-тегам

type Query

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

Query - form a query to the database

func (*Query) ByFields

func (q *Query) ByFields(where []string) *Query

ByFields - list of tags to be searched

func (*Query) Do

func (q *Query) Do() ([]interface{}, error)

Do - execute request (mandatory option)

func (*Query) Limit

func (q *Query) Limit(from int, how int) *Query

Limit - From the received list to return only ...

func (*Query) OrderBy

func (q *Query) OrderBy(tag string, asc int) *Query

OrderBy - tag (integer), by which the result will be sorted

type Spec

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

Spec - спецификация

type Storage

type Storage struct {
	sync.Mutex
	// contains filtered or unexported fields
}

Storage - base of structures

type Structer

type Structer struct {
	sync.Mutex
	// contains filtered or unexported fields
}

Structer - a structures storage

func New

func New(item interface{}, id string, tags []string) (*Structer, error)

New - create a new Structer item - это образец хранящейся структуры id - имя поля, которое будет id это поле должно быть строковым) tags - список тегов, это должны быть только int, string, []string поля структуры из по int полям можно будет потом сортировать, а по string и []string делать запросы на выборки.

func (*Structer) Add

func (e *Structer) Add(item interface{}) error

Add - add structure to storage This function is unsafe, since the user "outside" can change or delete the structure, and the database will not know anything about it.

func (*Structer) AddUnsafe

func (e *Structer) AddUnsafe(item interface{}) error

AddUnsafe - add structure to storage (unsafe)

func (*Structer) Count

func (e *Structer) Count() int

Count - number of stored structures

func (*Structer) Del

func (e *Structer) Del(id string) error

Del - delete structure from storage

func (*Structer) Find

func (e *Structer) Find() *Query

Find - create a new search query (by tags)

func (*Structer) Fragmentation

func (e *Structer) Fragmentation() int

Fragmentation - percentage of fragmentation, the ratio of the unfragmented amount to the total.

func (*Structer) Get

func (e *Structer) Get(id string) interface{}

Get - find structure by identifier

func (*Structer) Revision

func (e *Structer) Revision() error

Revision - garbage collection

func (*Structer) Save

func (e *Structer) Save(path string) error

Save - save the data store in a file (gob)

func (*Structer) Update

func (e *Structer) Update(itemNew interface{}) error

Update - replace structure

type Tags

type Tags struct {
	sync.Mutex
	// contains filtered or unexported fields
}

Tags - store subtags Хранилище всех тегов (под каждый тег выделяется Mark)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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