indexdb

package
v0.2.5 Latest Latest
Warning

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

Go to latest
Published: Jan 19, 2017 License: MIT Imports: 10 Imported by: 0

Documentation

Overview

Package indexdb handles the indexes storage.

Design

The DB is a leveldb instance, and the key-value format is:

|--- Key --|------------------ Value (24) -------------------|
+----------+-----------+-----------+-----------+-------------+
| Name (X) |  Link (4) | Stamp (4) | Score (8) | Average (8) |
+----------+-----------+-----------+-----------+-------------+

Cache

To access indexes faster, indexes are cached in memory, in a trie with goroutine safety.

Read operations are in cache.

Write operations are to persistence and cache.

Index

Constants

View Source
const MaxNumIndex = 16 * 1024 * 1024

MaxNumIndex is the max value of the number indexes this db can handle. Note that this number has no other meanings, just a limitation of the indexes capacity, it can be larger, theoretically can be MaxUint32.

Variables

View Source
var (
	// ErrNotFound is returned when requested data not found.
	ErrNotFound = errors.New("indexdb: not found")
	// ErrCorrupted is returned when corrupted data found.
	ErrCorrupted = errors.New("indexdb: corrupted data found")
	// ErrNoLink is returned when the index to put has no link.
	ErrNoLink = errors.New("indexdb: no link")
)

Functions

This section is empty.

Types

type DB

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

DB handles indexes storage.

func Open

func Open(fileName string, opts *Options) (*DB, error)

Open a DB by fileName.

func (*DB) All

func (db *DB) All() (l []*models.Index)

All returns all indexes.

func (*DB) Close

func (db *DB) Close() error

Close the DB.

func (*DB) Delete

func (db *DB) Delete(name string) error

Delete an index by name.

func (*DB) Filter

func (db *DB) Filter(pattern string) (l []*models.Index)

Filter indexes by pattern.

func (*DB) Get

func (db *DB) Get(name string) (*models.Index, error)

Get an index by name.

func (*DB) Has added in v0.1.9

func (db *DB) Has(name string) bool

Has checks if an index is in db.

func (*DB) Len added in v0.0.5

func (db *DB) Len() int

Len returns the number of indexes.

func (*DB) NumFilter added in v0.2.1

func (db *DB) NumFilter(pattern string) int

NumFilter filters the number of indexes by pattern.

func (*DB) Put

func (db *DB) Put(idx *models.Index) error

Put an index into db.

type Options added in v0.2.2

type Options struct {
	Expiration uint32
}

Options is to open DB.

Jump to

Keyboard shortcuts

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