Documentation ¶
Index ¶
- Constants
- type Bytes
- type Comp
- type Data
- type DataFac
- type DataMan
- type Database
- func (base *Database) CloseBase()
- func (base *Database) CreateDataMan(fac DataFac) *DataMan
- func (base *Database) CreateIndex(keySize int) FilePos
- func (base *Database) DeleteIndex(ref FilePos)
- func (base *Database) End() FilePos
- func (base *Database) OpenIndex(ref FilePos, man *KeyManager, f DataFac) *Index
- func (base *Database) PlaceNb() int
- func (base *Database) ReadPlace(place int) int64
- func (base *Database) UpdateBase()
- func (base *Database) WritePlace(place int, val int64)
- type Factorer
- type Factory
- type File
- type FilePos
- type Filer
- type Index
- type IndexReader
- func (ir *IndexReader) Clone() *IndexReader
- func (ir *IndexReader) CurrentKey() Data
- func (ir *IndexReader) Ind() *Index
- func (ir *IndexReader) Next()
- func (ir *IndexReader) PosSet() bool
- func (ir *IndexReader) Previous()
- func (ir *IndexReader) ReadValue() FilePos
- func (ir *IndexReader) ResetPos()
- func (ir *IndexReader) Search(key Data) bool
- type IndexWriter
- type KeyManager
- type KeyManagerer
- type Reader
- func (r *Reader) InBool() bool
- func (r *Reader) InByte() byte
- func (r *Reader) InBytes(len int) Bytes
- func (r *Reader) InFilePos() FilePos
- func (r *Reader) InFloat32() float32
- func (r *Reader) InFloat64() float64
- func (r *Reader) InInt16() int16
- func (r *Reader) InInt32() int32
- func (r *Reader) InInt64() int64
- func (r *Reader) InInt8() int8
- func (r *Reader) InString() string
- func (r *Reader) InStringLen() int
- func (r *Reader) InUint16() uint16
- func (r *Reader) InUint32() uint32
- func (r *Reader) InUint64() uint64
- func (r *Reader) Len() int
- func (r *Reader) Pos() int
- type String
- type StringComparer
- type StringFac
- type Writer
- func (w *Writer) OutBool(b bool)
- func (w *Writer) OutByte(c byte)
- func (w *Writer) OutBytes(b Bytes)
- func (w *Writer) OutFilePos(n FilePos)
- func (w *Writer) OutFloat32(r float32)
- func (w *Writer) OutFloat64(r float64)
- func (w *Writer) OutInt16(n int16)
- func (w *Writer) OutInt32(n int32)
- func (w *Writer) OutInt64(n int64)
- func (w *Writer) OutInt8(c int8)
- func (w *Writer) OutString(c string)
- func (w *Writer) OutUint16(n uint16)
- func (w *Writer) OutUint32(n uint32)
- func (w *Writer) OutUint64(n uint64)
Constants ¶
const ( // Nil pointer in a database. BNil = FilePos(0) // Sizes of data in bytes. BOS = 1 // bool size. BYS = 1 // byte size. SIS = 2 // int16 size. INS = 4 // int32 size. LIS = 8 // int64 size. SRS = 4 // float32 size. RES = 8 // float64 size. )
const ( // Comp; result of a comparaison. Lt = Comp(-1) // Less than. Eq = Comp(0) // Equal. Gt = Comp(+1) // Greater than. )
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type DataMan ¶
type DataMan struct {
// contains filtered or unexported fields
}
Manager of Data
func (*DataMan) AllocateData ¶
Consider using WriteAllocateData instead. Allocate a cluster for data, managed by m, in the database of m, and return its position. Warning: AllocateData calls data.Write to find the size of data, be sure the value of data can be written and has its correct size.
func (*DataMan) AllocateSize ¶
Consider using AllocateData or, better, WriteAllocateData instead. Allocate a cluster of size size, managed by m, in the database of m, and return its position. *)
func (*DataMan) WriteAllocateData ¶
Allocate a cluster for data, managed by m, in the database of m, and write data into it; return the position of the allocated cluster.
type Database ¶
type Database struct {
// contains filtered or unexported fields
}
A database
func (*Database) CreateDataMan ¶
Create and return a new manager of the data created by fac in the database base.
func (*Database) CreateIndex ¶
Create a new index in the database base and return its reference, but do not open it. keySize is the size of keys. If keys have a fixed size, put this size in keySize. If the size of keys does not vary much, put the greatest size in keySize. If the greatest size of keys is unknown, or if this size vary much, or if you want to use prefixes, put zero in keySize: you'll have to fix the size of each key later.
func (*Database) DeleteIndex ¶
Delete the index at position ref in the database base; this index must have been closed.
func (*Database) OpenIndex ¶
func (base *Database) OpenIndex(ref FilePos, man *KeyManager, f DataFac) *Index
Open and return an index created with the reference ref by Database.CreateIndex in the database base. man is the key manager of the index and f is the factory of its keys. The current position of the index is reset.
func (*Database) ReadPlace ¶
Read and return the content of the fixed place place of the database base. The first place has number 0.
func (*Database) WritePlace ¶
Write val in the fixed place place of the database base. The first place has number 0.
type Factorer ¶
type Factorer interface { // Create a file with name nF. Don't open this file. Create(nF string) bool // Open a file with name nF and return this file. Return nil if the file does not exist. Open(nF string) *File }
Interface for a Factory.
type Factory ¶
type Factory struct {
Factorer
}
Factory for files and databases.
func (*Factory) CloseBase ¶
Close, with the help of fac, the database created in the file of name nF, if it exists and is open. It is a rescue func. Use it only in case of an accidentally kept open database. Normally, use Database.CloseBase.
func (*Factory) CreateBase ¶
Create a new file of name nF, with the help of fac, and a database inside this file, with placeNb fixed places. Don't open this database. Fixed places are locations where can be recorded integers, i.e. data pointers.
type Filer ¶
type Filer interface { // Close the file. Close() // Flush the file on disk. Flush() // Set the reading position of the file to pos; the first position is 0. PosReader(pos FilePos) // Read an array of n bytes from the file at reading position. Read(n int) Bytes // Set the writing position of the file to pos; the first position is 0. PosWriter(pos FilePos) // Write the array a to the file at writing position. Write(b Bytes) // Return the length of the file. End() FilePos // Truncate the file at the length end. Truncate(end FilePos) // Read and return a float64 from the slice b at position pos; put pos at the position following the float64. BytesToFloat64(b Bytes, pos *int) float64 // Read and return a float32 from the slice b at position pos; put pos at the position following the float32. BytesToFloat32(b Bytes, pos *int) float32 // Return a pointer to a slice of bytes coding for f. Float64ToBytes(f float64) Bytes // Return a pointer to a slice of bytes coding for f. Float32ToBytes(f float32) Bytes }
Interface for file management.
type Index ¶
type Index struct {
// contains filtered or unexported fields
}
Index, structured as a btree.
func (*Index) NewReader ¶
func (ind *Index) NewReader() *IndexReader
Create a new Reader for ind. A Reader keeps a position in an Index and can update this position or read values there.
func (*Index) NumberOfKeys ¶
Return the number of different keys in ind
func (*Index) Writer ¶
func (ind *Index) Writer() *IndexWriter
Return the Writer of ind. A Writer keeps a position in an Index and can update this position or read/write values there.
type IndexReader ¶
type IndexReader struct {
// contains filtered or unexported fields
}
Reader of an index; each index may create several independant readers.
func (*IndexReader) CurrentKey ¶
func (ir *IndexReader) CurrentKey() Data
Return the value of the key in the current position of ir, or nil if the current position of ir is reset.
func (*IndexReader) Next ¶
func (ir *IndexReader) Next()
Position ir on the next key. If the current position is reset, ir is positioned on the first key. If ir is positioned on the last key, its current position becomes reset.
func (*IndexReader) PosSet ¶
func (ir *IndexReader) PosSet() bool
Test if ir is positioned on a key (return true) or if its current position is reset (false returned).
func (*IndexReader) Previous ¶
func (ir *IndexReader) Previous()
Position ir on the previous key. If the current position is reset, ir is positioned on the last key. If ir is positioned on the first key, its current position becomes reset.
func (*IndexReader) ReadValue ¶
func (ir *IndexReader) ReadValue() FilePos
Read, at the current position of ir, the associated reference of the Data of its Index and return it. When a new key is inserted, the reference which is initially attached to it has the value BNil. The reset position of an index has, itself, an associated reference, legible by IndexReader.ReadValue.
func (*IndexReader) ResetPos ¶
func (ir *IndexReader) ResetPos()
Reset the current position of ir. After this action, ir.PosSet() returns false.
func (*IndexReader) Search ¶
func (ir *IndexReader) Search(key Data) bool
Seek in the index of ir the key key. The result indicates if the key was found. Fix the current position of ir on the found key or on the key which is immediately after the sought key in the event of unfruitful search.
type IndexWriter ¶
type IndexWriter struct {
IndexReader // An IndexWriter can read too.
}
Writer of an index; each index owns only one writer.
func (*IndexWriter) Erase ¶
func (iw *IndexWriter) Erase(key Data) bool
Erase from the index of iw the key key. If key does not belong to the index, ind.Erase does nothing and returns false, otherwise it returns true. If the current position of iw was on the erased key, it is reset.
func (*IndexWriter) SearchIns ¶
func (iw *IndexWriter) SearchIns(key Data) bool
Seek in the index of iw the key key and insert it if it is not there already. The result indicates if the key was found. Fix the current position of iw on the key found or inserted.
func (*IndexWriter) WriteValue ¶
func (iw *IndexWriter) WriteValue(val FilePos)
Write on the current position of iw the associated reference val of a Data into its Index. When a new key is inserted, the data which is initially attached to it has the value BNil. The reset position of an index has, itself, a associated data, modifiable by IndexWriter.WriteValue.
type KeyManager ¶
type KeyManager struct { KeyManagerer // contains filtered or unexported fields }
Manager of index keys.
type KeyManagerer ¶
type KeyManagerer interface { // Comparison method. s1 and s2 are the keys to be compared. The result can be lt (s1 < s2), eq (s1 = s2) or gt (s1 > s2). KeyManagerer.CompP must induce a total order on the set of keys. CompP(s1, s2 Data) Comp // Create a prefix of a key. On input key1 and key2 are two keys, with key1 < key2. On output, key2 may be modified, but cannot be enlarged, so that it becomes a prefix of its previous value. A prefix Pref(key1, key2) of the key key2 in relation to the key key1 is defined by: // 1) Pref(key1, key2) is a key, which can be compared to other keys by the mean of the method KeyManager.CompP; // 2) Pref(key1, key2) is the shortest key with key1 < Pref(key1, key2) <= key2; // 3) key1 may have a null length and, in this case, must be considered less than any other key. // Prefixes are useful if keys are long or if their lengths vary much. In this case, if KeyManager.PrefP is instantiated, database is shorter and searches are faster. PrefP(key1 Data, key2 *Data) }
Interface for managers of index keys.
type Reader ¶
type Reader struct {
// contains filtered or unexported fields
}
Reader of a byte stream.
func (*Reader) InStringLen ¶
Read a string length from the input stream; preserves the position in the stream.
type String ¶
type String struct {
C string
}
String, satisfies Data.
func StringPrefP ¶
func StringPrefP(key1, key2 *String, compare StringComparer) *String
Create a prefix of the String key2, in relation with key1 and the comparison function compare; see PrefP.
type Writer ¶
type Writer struct {
// contains filtered or unexported fields
}
Writer on a byte stream.
func (*Writer) OutFilePos ¶
Write a FilePos to the output stream.
func (*Writer) OutFloat32 ¶
Write a float32 to the output stream. Use File.Float32ToBytes. *)
func (*Writer) OutFloat64 ¶
Write a float64 to the output stream. Use File.Float64ToBytes. *)