indexes

package
v0.36.19 Latest Latest
Warning

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

Go to latest
Published: Dec 25, 2025 License: Unlicense Imports: 5 Imported by: 0

Documentation

Index

Constants

View Source
const (
	EventPrefix            = I("evt")
	SmallEventPrefix       = I("sev") // small event with inline data (<=384 bytes)
	ReplaceableEventPrefix = I("rev") // replaceable event (kinds 0,3,10000-19999) with inline data
	AddressableEventPrefix = I("aev") // addressable event (kinds 30000-39999) with inline data
	IdPrefix               = I("eid")
	FullIdPubkeyPrefix     = I("fpc") // full id, pubkey, created at

	CreatedAtPrefix  = I("c--") // created at
	KindPrefix       = I("kc-") // kind, created at
	PubkeyPrefix     = I("pc-") // pubkey, created at
	KindPubkeyPrefix = I("kpc") // kind, pubkey, created at

	TagPrefix           = I("tc-") // tag, created at
	TagKindPrefix       = I("tkc") // tag, kind, created at
	TagPubkeyPrefix     = I("tpc") // tag, pubkey, created at
	TagKindPubkeyPrefix = I("tkp") // tag, kind, pubkey, created at

	WordPrefix       = I("wrd") // word hash, serial
	ExpirationPrefix = I("exp") // timestamp of expiration
	VersionPrefix    = I("ver") // database version number, for triggering reindexes when new keys are added (policy is add-only).

	// Pubkey graph indexes
	PubkeySerialPrefix     = I("pks") // pubkey hash -> pubkey serial
	SerialPubkeyPrefix     = I("spk") // pubkey serial -> pubkey hash (full 32 bytes)
	EventPubkeyGraphPrefix = I("epg") // event serial -> pubkey serial (graph edges)
	PubkeyEventGraphPrefix = I("peg") // pubkey serial -> event serial (reverse edges)

	// Compact event storage indexes
	SerialEventIdPrefix = I("sei") // event serial -> full 32-byte event ID
	CompactEventPrefix  = I("cmp") // compact event storage with serial references

	// Event-to-event graph indexes (for e-tag references)
	EventEventGraphPrefix = I("eeg") // source event serial -> target event serial (outbound e-tags)
	GraphEventEventPrefix = I("gee") // target event serial -> source event serial (reverse e-tags)
)

Variables

View Source
var AddressableEvent = next()

AddressableEvent stores parameterized replaceable events (kinds 30000-39999) with inline data. Optimized storage for addressable events identified by pubkey+kind+d-tag. Key format enables direct lookup without additional index traversal.

prefix|8 pubkey_hash|2 kind|8 dtag_hash|2 size_uint16|data (variable length, max 384 bytes)
View Source
var CompactEvent = next()

CompactEvent stores events using serial references instead of full IDs/pubkeys. This dramatically reduces storage size by replacing: - 32-byte event ID with 5-byte serial - 32-byte author pubkey with 5-byte pubkey serial - 32-byte e-tag values with 5-byte event serials (or full ID if unknown) - 32-byte p-tag values with 5-byte pubkey serials

Format: cmp|5 serial|compact event data (variable length)

View Source
var CreatedAt = next()

CreatedAt is an index that allows search for the timestamp on the event.

3 prefix|8 timestamp|5 serial
View Source
var Event = next()

Event is the whole event stored in binary format

prefix|5 serial - event in binary format
View Source
var EventEventGraph = next()

EventEventGraph creates a bidirectional graph edge between events via e-tags. This stores source_event_serial -> target_event_serial relationships with event kind and direction. Used for thread traversal and finding replies/reactions/reposts to events. Direction: 0=outbound (this event references target)

3 prefix|5 source event serial|5 target event serial|2 kind|1 direction
View Source
var EventPubkeyGraph = next()

EventPubkeyGraph creates a bidirectional graph edge between events and pubkeys This stores event_serial -> pubkey_serial relationships with event kind and direction Direction: 0=author, 1=p-tag-out (event references pubkey)

3 prefix|5 event serial|5 pubkey serial|2 kind|1 direction
View Source
var Expiration = next()

Expiration

3 prefix|8 timestamp|5 serial

View Source
var FullIdPubkey = next()

FullIdPubkey is an index designed to enable sorting and filtering of results found via other indexes, without having to decode the event.

3 prefix|5 serial|32 ID|8 pubkey hash|8 timestamp
View Source
var GraphEventEvent = next()

GraphEventEvent creates the reverse edge: target_event_serial -> source_event_serial with kind and direction. This enables querying all events that reference a target event (e.g., all replies to a post). Direction: 1=inbound (target is referenced by source)

3 prefix|5 target event serial|2 kind|1 direction|5 source event serial
View Source
var Id = next()

Id contains a truncated 8-byte hash of an event index. This is the secondary key of an event, the primary key is the serial found in the Event.

3 prefix|8 ID hash|5 serial
View Source
var Kind = next()

Kind

3 prefix|2 kind|8 timestamp|5 serial
View Source
var KindPubkey = next()

KindPubkey

3 prefix|2 kind|8 pubkey hash|8 timestamp|5 serial
View Source
var Pubkey = next()

Pubkey is a composite index that allows search by pubkey filtered by timestamp.

3 prefix|8 pubkey hash|8 timestamp|5 serial
View Source
var PubkeyEventGraph = next()

PubkeyEventGraph creates the reverse edge: pubkey_serial -> event_serial with event kind and direction This enables querying all events related to a pubkey, optionally filtered by kind and direction Direction: 0=is-author, 2=p-tag-in (pubkey is referenced by event)

3 prefix|5 pubkey serial|2 kind|1 direction|5 event serial
View Source
var PubkeySerial = next()

PubkeySerial maps a pubkey hash to its unique serial number

3 prefix|8 pubkey hash|5 serial
View Source
var ReplaceableEvent = next()

ReplaceableEvent stores replaceable events (kinds 0,3,10000-19999) with inline data. Optimized storage for metadata events that are frequently replaced. Key format enables direct lookup by pubkey+kind without additional index traversal.

prefix|8 pubkey_hash|2 kind|2 size_uint16|data (variable length, max 384 bytes)
View Source
var SerialEventId = next()

SerialEventId maps an event serial to its full 32-byte event ID. This enables reconstruction of the original event ID from compact storage. The event ID is stored as the value (32 bytes), not inline in the key.

3 prefix|5 serial -> 32 byte event ID value
View Source
var SerialPubkey = next()

SerialPubkey maps a pubkey serial to the full 32-byte pubkey This stores the full pubkey (32 bytes) as the value, not inline

3 prefix|5 serial -> 32 byte pubkey value
View Source
var SmallEvent = next()

SmallEvent stores events <=384 bytes with inline data to avoid double lookup. This is a Reiser4-inspired optimization for small event packing. 384 bytes covers: ID(32) + Pubkey(32) + Sig(64) + basic fields + small content

prefix|5 serial|2 size_uint16|data (variable length, max 384 bytes)
View Source
var Tag = next()

Tag allows searching for a tag and filter by timestamp.

3 prefix|1 key letter|8 value hash|8 timestamp|5 serial
View Source
var TagKind = next()

TagKind

3 prefix|1 key letter|8 value hash|2 kind|8 timestamp|5 serial
View Source
var TagKindPubkey = next()

TagKindPubkey

3 prefix|1 key letter|8 value hash|2 kind|8 pubkey hash|8 bytes timestamp|5 serial
View Source
var TagPubkey = next()

TagPubkey allows searching for a pubkey, tag and timestamp.

3 prefix|1 key letter|8 value hash|8 pubkey hash|8 timestamp|5 serial
View Source
var Version = next()

Version

3 prefix|4 version

View Source
var Word = next()

Word index for tokenized search terms

3 prefix|8 word-hash|5 serial

Functions

func AddressableEventVars added in v0.28.0

func AddressableEventVars() (p *types.PubHash, ki *types.Uint16, d *types.Ident)

func CompactEventVars added in v0.33.0

func CompactEventVars() (ser *types.Uint40)

func CreatedAtVars

func CreatedAtVars() (ca *types.Uint64, ser *types.Uint40)

func EventEventGraphVars added in v0.34.0

func EventEventGraphVars() (srcSer *types.Uint40, tgtSer *types.Uint40, kind *types.Uint16, direction *types.Letter)

func EventPubkeyGraphVars added in v0.29.11

func EventPubkeyGraphVars() (eventSer *types.Uint40, pubkeySer *types.Uint40, kind *types.Uint16, direction *types.Letter)

func EventVars

func EventVars() (ser *types.Uint40)

func ExpirationVars

func ExpirationVars() (
	exp *types.Uint64, ser *types.Uint40,
)

func FullIdPubkeyVars

func FullIdPubkeyVars() (
	ser *types.Uint40, fid *types.Id, p *types.PubHash, ca *types.Uint64,
)

func GraphEventEventVars added in v0.34.0

func GraphEventEventVars() (tgtSer *types.Uint40, kind *types.Uint16, direction *types.Letter, srcSer *types.Uint40)

func IdVars

func IdVars() (id *types.IdHash, ser *types.Uint40)

func Identify

func Identify(r io.Reader) (i int, err error)

func KindPubkeyVars

func KindPubkeyVars() (
	ki *types.Uint16, p *types.PubHash, ca *types.Uint64, ser *types.Uint40,
)

func KindVars

func KindVars() (ki *types.Uint16, ca *types.Uint64, ser *types.Uint40)

func PubkeyEventGraphVars added in v0.29.11

func PubkeyEventGraphVars() (pubkeySer *types.Uint40, kind *types.Uint16, direction *types.Letter, eventSer *types.Uint40)

func PubkeySerialVars added in v0.29.11

func PubkeySerialVars() (p *types.PubHash, ser *types.Uint40)

func PubkeyVars

func PubkeyVars() (p *types.PubHash, ca *types.Uint64, ser *types.Uint40)

func ReplaceableEventVars added in v0.28.0

func ReplaceableEventVars() (p *types.PubHash, ki *types.Uint16)

func SerialEventIdVars added in v0.33.0

func SerialEventIdVars() (ser *types.Uint40)

func SerialPubkeyVars added in v0.29.11

func SerialPubkeyVars() (ser *types.Uint40)

func SmallEventVars added in v0.28.0

func SmallEventVars() (ser *types.Uint40)

func TagKindPubkeyVars

func TagKindPubkeyVars() (
	k *types.Letter, v *types.Ident, ki *types.Uint16, p *types.PubHash,
	ca *types.Uint64,
	ser *types.Uint40,
)

func TagKindVars

func TagKindVars() (
	k *types.Letter, v *types.Ident, ki *types.Uint16, ca *types.Uint64,
	ser *types.Uint40,
)

func TagPubkeyVars

func TagPubkeyVars() (
	k *types.Letter, v *types.Ident, p *types.PubHash, ca *types.Uint64,
	ser *types.Uint40,
)

func TagVars

func TagVars() (
	k *types.Letter, v *types.Ident, ca *types.Uint64, ser *types.Uint40,
)

func VersionVars

func VersionVars() (
	ver *types.Uint32,
)

func WordVars added in v0.9.0

func WordVars() (w *types.Word, ser *types.Uint40)

Types

type Encs

type Encs []codec.I

type I

type I string

func Prefix

func Prefix(prf int) (i I)

Prefix returns the three byte human-readable prefixes that go in front of database indexes.

func (I) Write

func (i I) Write(w io.Writer) (n int, err error)

type P

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

func NewPrefix

func NewPrefix(prf ...int) (p *P)

func (*P) Bytes

func (p *P) Bytes() (b []byte)

func (*P) MarshalWrite

func (p *P) MarshalWrite(w io.Writer) (err error)

func (*P) UnmarshalRead

func (p *P) UnmarshalRead(r io.Reader) (err error)

type T

type T struct{ Encs }

T is a wrapper around an array of codec.I. The caller provides the Encs so they can then call the accessor methods of the codec.I implementation.

func AddressableEventDec added in v0.28.0

func AddressableEventDec(p *types.PubHash, ki *types.Uint16, d *types.Ident) (enc *T)

func AddressableEventEnc added in v0.28.0

func AddressableEventEnc(p *types.PubHash, ki *types.Uint16, d *types.Ident) (enc *T)

func CompactEventDec added in v0.33.0

func CompactEventDec(ser *types.Uint40) (enc *T)

func CompactEventEnc added in v0.33.0

func CompactEventEnc(ser *types.Uint40) (enc *T)

func CreatedAtDec

func CreatedAtDec(ca *types.Uint64, ser *types.Uint40) (enc *T)

func CreatedAtEnc

func CreatedAtEnc(ca *types.Uint64, ser *types.Uint40) (enc *T)

func EventDec

func EventDec(ser *types.Uint40) (enc *T)

func EventEnc

func EventEnc(ser *types.Uint40) (enc *T)

func EventEventGraphDec added in v0.34.0

func EventEventGraphDec(srcSer *types.Uint40, tgtSer *types.Uint40, kind *types.Uint16, direction *types.Letter) (enc *T)

func EventEventGraphEnc added in v0.34.0

func EventEventGraphEnc(srcSer *types.Uint40, tgtSer *types.Uint40, kind *types.Uint16, direction *types.Letter) (enc *T)

func EventPubkeyGraphDec added in v0.29.11

func EventPubkeyGraphDec(eventSer *types.Uint40, pubkeySer *types.Uint40, kind *types.Uint16, direction *types.Letter) (enc *T)

func EventPubkeyGraphEnc added in v0.29.11

func EventPubkeyGraphEnc(eventSer *types.Uint40, pubkeySer *types.Uint40, kind *types.Uint16, direction *types.Letter) (enc *T)

func ExpirationDec

func ExpirationDec(
	exp *types.Uint64, ser *types.Uint40,
) (enc *T)

func ExpirationEnc

func ExpirationEnc(
	exp *types.Uint64, ser *types.Uint40,
) (enc *T)

func FullIdPubkeyDec

func FullIdPubkeyDec(
	ser *types.Uint40, fid *types.Id, p *types.PubHash, ca *types.Uint64,
) (enc *T)

func FullIdPubkeyEnc

func FullIdPubkeyEnc(
	ser *types.Uint40, fid *types.Id, p *types.PubHash, ca *types.Uint64,
) (enc *T)

func GraphEventEventDec added in v0.34.0

func GraphEventEventDec(tgtSer *types.Uint40, kind *types.Uint16, direction *types.Letter, srcSer *types.Uint40) (enc *T)

func GraphEventEventEnc added in v0.34.0

func GraphEventEventEnc(tgtSer *types.Uint40, kind *types.Uint16, direction *types.Letter, srcSer *types.Uint40) (enc *T)

func IdDec

func IdDec(id *types.IdHash, ser *types.Uint40) (enc *T)

func IdEnc

func IdEnc(id *types.IdHash, ser *types.Uint40) (enc *T)

func KindDec

func KindDec(ki *types.Uint16, ca *types.Uint64, ser *types.Uint40) (enc *T)

func KindEnc

func KindEnc(ki *types.Uint16, ca *types.Uint64, ser *types.Uint40) (enc *T)

func KindPubkeyDec

func KindPubkeyDec(
	ki *types.Uint16, p *types.PubHash, ca *types.Uint64, ser *types.Uint40,
) (enc *T)

func KindPubkeyEnc

func KindPubkeyEnc(
	ki *types.Uint16, p *types.PubHash, ca *types.Uint64, ser *types.Uint40,
) (enc *T)

func New

func New(encoders ...codec.I) (i *T)

New creates a new indexes.T. The helper functions below have an encode and decode variant, the decode variant doesn't add the prefix encoder because it has been read by Identify or just is being read, and found because it was written for the prefix in the iteration.

func PubkeyDec

func PubkeyDec(p *types.PubHash, ca *types.Uint64, ser *types.Uint40) (enc *T)

func PubkeyEnc

func PubkeyEnc(p *types.PubHash, ca *types.Uint64, ser *types.Uint40) (enc *T)

func PubkeyEventGraphDec added in v0.29.11

func PubkeyEventGraphDec(pubkeySer *types.Uint40, kind *types.Uint16, direction *types.Letter, eventSer *types.Uint40) (enc *T)

func PubkeyEventGraphEnc added in v0.29.11

func PubkeyEventGraphEnc(pubkeySer *types.Uint40, kind *types.Uint16, direction *types.Letter, eventSer *types.Uint40) (enc *T)

func PubkeySerialDec added in v0.29.11

func PubkeySerialDec(p *types.PubHash, ser *types.Uint40) (enc *T)

func PubkeySerialEnc added in v0.29.11

func PubkeySerialEnc(p *types.PubHash, ser *types.Uint40) (enc *T)

func ReplaceableEventDec added in v0.28.0

func ReplaceableEventDec(p *types.PubHash, ki *types.Uint16) (enc *T)

func ReplaceableEventEnc added in v0.28.0

func ReplaceableEventEnc(p *types.PubHash, ki *types.Uint16) (enc *T)

func SerialEventIdDec added in v0.33.0

func SerialEventIdDec(ser *types.Uint40) (enc *T)

func SerialEventIdEnc added in v0.33.0

func SerialEventIdEnc(ser *types.Uint40) (enc *T)

func SerialPubkeyDec added in v0.29.11

func SerialPubkeyDec(ser *types.Uint40) (enc *T)

func SerialPubkeyEnc added in v0.29.11

func SerialPubkeyEnc(ser *types.Uint40) (enc *T)

func SmallEventDec added in v0.28.0

func SmallEventDec(ser *types.Uint40) (enc *T)

func SmallEventEnc added in v0.28.0

func SmallEventEnc(ser *types.Uint40) (enc *T)

func TagDec

func TagDec(
	k *types.Letter, v *types.Ident, ca *types.Uint64, ser *types.Uint40,
) (enc *T)

func TagEnc

func TagEnc(
	k *types.Letter, v *types.Ident, ca *types.Uint64, ser *types.Uint40,
) (enc *T)

func TagKindDec

func TagKindDec(
	k *types.Letter, v *types.Ident, ki *types.Uint16, ca *types.Uint64,
	ser *types.Uint40,
) (enc *T)

func TagKindEnc

func TagKindEnc(
	k *types.Letter, v *types.Ident, ki *types.Uint16, ca *types.Uint64,
	ser *types.Uint40,
) (enc *T)

func TagKindPubkeyDec

func TagKindPubkeyDec(
	k *types.Letter, v *types.Ident, ki *types.Uint16, p *types.PubHash,
	ca *types.Uint64,
	ser *types.Uint40,
) (enc *T)

func TagKindPubkeyEnc

func TagKindPubkeyEnc(
	k *types.Letter, v *types.Ident, ki *types.Uint16, p *types.PubHash,
	ca *types.Uint64,
	ser *types.Uint40,
) (enc *T)

func TagPubkeyDec

func TagPubkeyDec(
	k *types.Letter, v *types.Ident, p *types.PubHash, ca *types.Uint64,
	ser *types.Uint40,
) (enc *T)

func TagPubkeyEnc

func TagPubkeyEnc(
	k *types.Letter, v *types.Ident, p *types.PubHash, ca *types.Uint64,
	ser *types.Uint40,
) (enc *T)

func VersionDec

func VersionDec(
	ver *types.Uint32,
) (enc *T)

func VersionEnc

func VersionEnc(
	ver *types.Uint32,
) (enc *T)

func WordDec added in v0.9.0

func WordDec(w *types.Word, ser *types.Uint40) (enc *T)

func WordEnc added in v0.9.0

func WordEnc(w *types.Word, ser *types.Uint40) (enc *T)

func (*T) MarshalWrite

func (t *T) MarshalWrite(w io.Writer) (err error)

func (*T) UnmarshalRead

func (t *T) UnmarshalRead(r io.Reader) (err error)

Source Files

  • keys.go

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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