doclite

package
v0.0.0-...-059bd83 Latest Latest
Warning

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

Go to latest
Published: Sep 21, 2020 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// MinKeys minimum number of keys in a node
	// this automatically makes the upper bound of 2 * Minkeys
	MinKeys = pageSize / dataSize

	// BtreeMaxSize is maximum size of disk space btree could take
	// before it overflows
	BtreeMaxSize = 10000000
)

Variables

View Source
var (
	// MaxCacheSize is max amount of document that can be in memory
	MaxCacheSize = 30
)

Functions

This section is empty.

Types

type Btree

type Btree struct {
	Name           string
	NumDocuments   int64
	NumRoots       int
	SubCollections map[string]*Btree
	Pool           []int64 // pool of available ids
	Pages          []int64 // the pages this bree occupies
	// contains filtered or unexported fields
}

A Btree object

func (*Btree) Delete

func (t *Btree) Delete(id int64)

Delete an item into the btree with the specified key

func (*Btree) DeleteAll

func (t *Btree) DeleteAll(filter, doc interface{})

DeleteAll deletes all document matching a criterion

func (*Btree) Find

func (t *Btree) Find(id int64) (*Node, error)

Find an item into the btree with the specified key

func (*Btree) FindAll

func (t *Btree) FindAll(filter interface{}) *Cursor

FindAll finds items in the btree matching a filter and a doc

func (*Btree) Get

func (t *Btree) Get(name string) *Btree

Get returns a subcollection

func (*Btree) Insert

func (t *Btree) Insert(data []byte) int64

Insert an item into the btree with the specified key

func (*Btree) InsertOrUpdate

func (t *Btree) InsertOrUpdate(id int64, data []byte) int64

InsertOrUpdate update an item in the btree with the specified key if found insert it with a new id if found

func (*Btree) InsertSubCollection

func (t *Btree) InsertSubCollection(name string)

InsertSubCollection insert a newSubCollection to this btree

func (*Btree) Save

func (t *Btree) Save()

Save insert all cache node to into disk

func (*Btree) ShowCase

func (t *Btree) ShowCase()

ShowCase is used to tanverse this node

func (*Btree) Update

func (t *Btree) Update(id int64, data []byte) error

Update an item into the btree with the specified key

type Cache

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

Cache to hold document in memory .uses LRU cache policy

func NewCache

func NewCache(db *DB, tree *Btree) *Cache

NewCache initilize a new cache

func (*Cache) Add

func (c *Cache) Add(n *Node)

Add insert a new item into this cache

func (*Cache) Delete

func (c *Cache) Delete(id int64)

Delete remove item into this cache

func (*Cache) DeleteAll

func (c *Cache) DeleteAll(filter interface{}, doc interface{}) []int64

DeleteAll deletes all document matching filter

func (*Cache) Find

func (c *Cache) Find(filter interface{}, start int) ([]interface{}, int)

Find gets all nodes matching a criterions specified by filter

func (*Cache) Save

func (c *Cache) Save()

Save insert this cache to into disk

type CacheCursor

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

CacheCursor object supplies matching Nodes for a search

type Cursor

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

Cursor object supplies matching Nodes for a search

func NewCur

func NewCur() *Cursor

NewCur returns a new Cursor object

func (*Cursor) Next

func (c *Cursor) Next() interface{}

Next return the next matching node of filter

type DB

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

DB represents our database file

func OpenDB

func OpenDB(fileName string) *DB

OpenDB instantiate our database

func (*DB) Close

func (db *DB) Close() error

Close closes the database must be called before at exit

func (*DB) Connect

func (db *DB) Connect() *Btree

Connect start a connection to this data base for insertion and deletion

func (*DB) Save

func (db *DB) Save() error

Save saves all current changes on the database

type Document

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

Document type representing a document

func (*Document) Data

func (d *Document) Data() []byte

Data returns the conataining byte of a document for decoding

type Meta

type Meta struct {
	MagicString    []byte
	NofCollections int64 // add mutex

	OverflowSize       int64
	OverflowDataOffset int64
	RootTreeOffset     int64
	RootTreeSize       int64
	NumPages           int64 // add mutex
	// contains filtered or unexported fields
}

Meta represent the database file metadata

magic string is used to idenitify the database file
number of collection in this database
offset overflow bytes offset
number of overflow doc
number of overflow data
offset of the root btree

func (*Meta) String

func (m *Meta) String() string

type Node

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

The Node in our btree

func (*Node) Doc

func (n *Node) Doc() *Document

Doc returns the document for a node

func (*Node) String

func (n *Node) String() string

Jump to

Keyboard shortcuts

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