id

package
v0.18.0 Latest Latest
Warning

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

Go to latest
Published: Jul 11, 2024 License: EUPL-1.2 Imports: 6 Imported by: 1

Documentation

Overview

Package id provides zettel specific types, constants, and functions about zettel identifier.

Index

Constants

View Source
const (
	Invalid = Zid(0) // Invalid is a Zid that will never be valid
)

Some important ZettelIDs.

View Source
const (
	InvalidN = ZidN(0) // Invalid is a Zid that will never be valid
)

Some important ZettelIDs.

View Source
const TimestampLayout = "20060102150405"

TimestampLayout to transform a date into a Zid and into other internal dates.

Variables

View Source
var (
	ConfigurationZid  = MustParse(api.ZidConfiguration)
	BaseTemplateZid   = MustParse(api.ZidBaseTemplate)
	LoginTemplateZid  = MustParse(api.ZidLoginTemplate)
	ListTemplateZid   = MustParse(api.ZidListTemplate)
	ZettelTemplateZid = MustParse(api.ZidZettelTemplate)
	InfoTemplateZid   = MustParse(api.ZidInfoTemplate)
	FormTemplateZid   = MustParse(api.ZidFormTemplate)
	RenameTemplateZid = MustParse(api.ZidRenameTemplate)
	DeleteTemplateZid = MustParse(api.ZidDeleteTemplate)
	ErrorTemplateZid  = MustParse(api.ZidErrorTemplate)
	StartSxnZid       = MustParse(api.ZidSxnStart)
	BaseSxnZid        = MustParse(api.ZidSxnBase)
	PreludeSxnZid     = MustParse(api.ZidSxnPrelude)
	EmojiZid          = MustParse(api.ZidEmoji)
	TOCNewTemplateZid = MustParse(api.ZidTOCNewTemplate)
	DefaultHomeZid    = MustParse(api.ZidDefaultHome)
)

ZettelIDs that are used as Zid more than once.

Note: if you change some values, ensure that you also change them in the Constant box. They are mentioned there literally, because these constants are not available there.

Functions

func ParseUint

func ParseUint(s string) (uint64, error)

ParseUint interprets a string as a possible zettel identifier and returns its integer value.

func ParseUintN added in v0.18.0

func ParseUintN(s string) (uint64, error)

ParseUintN interprets a string as a possible zettel identifier and returns its integer value.

Types

type Digraph added in v0.14.0

type Digraph map[Zid]*Set

Digraph relates zettel identifier in a directional way.

func (Digraph) AddEdge added in v0.14.0

func (dg Digraph) AddEdge(fromZid, toZid Zid) Digraph

AddEdge adds a connection from `zid1` to `zid2`. Both vertices must be added before. Otherwise the function may panic.

func (Digraph) AddEgdes added in v0.14.0

func (dg Digraph) AddEgdes(edges EdgeSlice) Digraph

AddEgdes adds all given `Edge`s to the digraph.

In contrast to `AddEdge` the vertices must not exist before.

func (Digraph) AddVertex added in v0.14.0

func (dg Digraph) AddVertex(zid Zid) Digraph

AddVertex adds an edge / vertex to the digraph.

func (Digraph) Clone added in v0.15.0

func (dg Digraph) Clone() Digraph

Clone a digraph.

func (Digraph) Edges added in v0.14.0

func (dg Digraph) Edges() (es EdgeSlice)

Edges returns an unsorted slice of the edges of the digraph.

func (Digraph) Equal added in v0.14.0

func (dg Digraph) Equal(other Digraph) bool

Equal returns true if both digraphs have the same vertices and edges.

func (Digraph) HasVertex added in v0.14.0

func (dg Digraph) HasVertex(zid Zid) bool

HasVertex returns true, if `zid` is a vertex of the digraph.

func (Digraph) IsDAG added in v0.14.0

func (dg Digraph) IsDAG() (Zid, bool)

IsDAG returns a vertex and false, if the graph has a cycle containing the vertex.

func (Digraph) Originators added in v0.14.0

func (dg Digraph) Originators() *Set

Originators will return the set of all vertices that are not referenced a the to-part of an edge.

func (Digraph) ReachableVertices added in v0.14.0

func (dg Digraph) ReachableVertices(zid Zid) (tc *Set)

ReachableVertices calculates the set of all vertices that are reachable from the given `zid`.

func (Digraph) RemoveVertex added in v0.15.0

func (dg Digraph) RemoveVertex(zid Zid)

RemoveVertex removes a vertex and all its edges from the digraph.

func (Digraph) Reverse added in v0.15.0

func (dg Digraph) Reverse() (revDg Digraph)

Reverse returns a graph with reversed edges.

func (Digraph) SortReverse added in v0.14.0

func (dg Digraph) SortReverse() (sl Slice)

SortReverse returns a deterministic, topological, reverse sort of the digraph.

Works only if digraph is a DAG. Otherwise the algorithm will not terminate or returns an arbitrary value.

func (Digraph) Terminators added in v0.14.0

func (dg Digraph) Terminators() (terms *Set)

Terminators returns the set of all vertices that does not reference other vertices.

func (Digraph) TransitiveClosure added in v0.14.0

func (dg Digraph) TransitiveClosure(zid Zid) (tc Digraph)

TransitiveClosure calculates the sub-graph that is reachable from `zid`.

func (Digraph) Vertices added in v0.14.0

func (dg Digraph) Vertices() *Set

Vertices returns the set of all vertices.

type Edge added in v0.14.0

type Edge struct {
	From, To Zid
}

Edge is a pair of to vertices.

type EdgeSlice added in v0.14.0

type EdgeSlice []Edge

EdgeSlice is a slice of Edges

func (EdgeSlice) Equal added in v0.14.0

func (es EdgeSlice) Equal(other EdgeSlice) bool

Equal return true if both slices are the same.

func (EdgeSlice) Sort added in v0.14.0

func (es EdgeSlice) Sort() EdgeSlice

Sort the slice.

type Set

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

Set is a set of zettel identifier

func NewSet

func NewSet(zids ...Zid) *Set

NewSet returns a new set of identifier with the given initial values.

func NewSetCap

func NewSetCap(c int, zids ...Zid) *Set

NewSetCap returns a new set of identifier with the given capacity and initial values.

func (*Set) Add

func (s *Set) Add(zid Zid) *Set

Add adds a Add to the set.

func (*Set) AddSlice

func (s *Set) AddSlice(sl Slice) *Set

AddSlice adds all identifier of the given slice to the set.

func (*Set) Clone added in v0.14.0

func (s *Set) Clone() *Set

Clone returns a copy of the given set.

func (*Set) Contains

func (s *Set) Contains(zid Zid) bool

Contains return true if the set is non-nil and the set contains the given Zettel identifier.

func (*Set) ContainsOrNil added in v0.14.0

func (s *Set) ContainsOrNil(zid Zid) bool

ContainsOrNil return true if the set is nil or if the set contains the given Zettel identifier.

func (*Set) Diff added in v0.18.0

func (s *Set) Diff(other *Set) (newS, remS *Set)

Diff returns the difference sets between the two sets: the first difference set is the set of elements that are in other, but not in s; the second difference set is the set of element that are in s but not in other.

in other words: the first result is the set of elements from other that must be added to s; the second result is the set of elements that must be removed from s, so that s would have the same elemest as other.

func (*Set) Equal added in v0.14.0

func (s *Set) Equal(other *Set) bool

Equal returns true if the other set is equal to the given set.

func (*Set) ForEach added in v0.18.0

func (s *Set) ForEach(fn func(zid Zid))

ForEach calls the given function for each element of the set.

Every element is bigger than the previous one.

func (*Set) ISubstract added in v0.18.0

func (s *Set) ISubstract(other *Set)

ISubstract removes all zettel identifier from 's' that are in the set 'other'.

func (*Set) IUnion added in v0.18.0

func (s *Set) IUnion(other *Set) *Set

IUnion adds the elements of set other to s.

func (*Set) IntersectOrSet

func (s *Set) IntersectOrSet(other *Set) *Set

IntersectOrSet removes all zettel identifier that are not in the other set. Both sets can be modified by this method. One of them is the set returned. It contains the intersection of both, if s is not nil.

If s == nil, then the other set is always returned.

func (*Set) IsEmpty added in v0.18.0

func (s *Set) IsEmpty() bool

IsEmpty returns true, if the set conains no element.

func (*Set) Length added in v0.18.0

func (s *Set) Length() int

Length returns the number of elements in this set.

func (*Set) MetaString added in v0.18.0

func (s *Set) MetaString() string

MetaString returns a string representation of the set to be stored as metadata.

func (*Set) Optimize added in v0.18.0

func (s *Set) Optimize()

Optimize the amount of memory to store the set.

func (*Set) Pop added in v0.18.0

func (s *Set) Pop() (Zid, bool)

Pop return one arbitrary element of the set.

func (*Set) Remove

func (s *Set) Remove(zid Zid) *Set

Remove the identifier from the set.

func (*Set) SafeSorted added in v0.18.0

func (s *Set) SafeSorted() Slice

SafeSorted returns the set as a new sorted slice of zettel identifier.

func (*Set) String added in v0.14.0

func (s *Set) String() string

String returns a string representation of the set.

type Slice

type Slice []Zid

Slice is a sequence of zettel identifier. A special case is a sorted slice.

func (Slice) Clone added in v0.14.0

func (zs Slice) Clone() Slice

Clone a zettel identifier slice

func (Slice) Equal

func (zs Slice) Equal(other Slice) bool

Equal reports whether zs and other are the same length and contain the samle zettel identifier. A nil argument is equivalent to an empty slice.

func (Slice) MetaString added in v0.18.0

func (zs Slice) MetaString() string

MetaString returns the slice as a string to be store in metadata.

func (Slice) Sort

func (zs Slice) Sort()

Sort a slice of Zids.

type Zid

type Zid uint64

Zid is the internal identifier of a zettel. Typically, it is a time stamp of the form "YYYYMMDDHHmmSS" converted to an unsigned integer. A zettelstore implementation should try to set the last two digits to zero, e.g. the seconds should be zero,

func MustParse

func MustParse(s api.ZettelID) Zid

MustParse tries to interpret a string as a zettel identifier and returns its value or panics otherwise.

func New

func New(withSeconds bool) Zid

New returns a new zettel id based on the current time.

func Parse

func Parse(s string) (Zid, error)

Parse interprets a string as a zettel identification and returns its value.

func (Zid) Bytes

func (zid Zid) Bytes() []byte

Bytes converts the zettel identification to a byte slice of 14 digits. Only defined for valid ids.

func (Zid) IsValid

func (zid Zid) IsValid() bool

IsValid determines if zettel id is a valid one, e.g. consists of max. 14 digits.

func (Zid) String

func (zid Zid) String() string

String converts the zettel identification to a string of 14 digits. Only defined for valid ids.

func (Zid) ZettelID added in v0.17.0

func (zid Zid) ZettelID() api.ZettelID

ZettelID return the zettel identification as a api.ZettelID.

type ZidN added in v0.18.0

type ZidN uint32

ZidN is the internal identifier of a zettel. It is a number in the range 1..36^4-1 (1..1679615), as it is externally represented by four alphanumeric characters.

func MustParseN added in v0.18.0

func MustParseN(s api.ZettelID) ZidN

MustParseN tries to interpret a string as a zettel identifier and returns its value or panics otherwise.

func ParseN added in v0.18.0

func ParseN(s string) (ZidN, error)

ParseN interprets a string as a zettel identification and returns its value.

func (ZidN) Bytes added in v0.18.0

func (zid ZidN) Bytes() []byte

Bytes converts the zettel identification to a byte slice of 14 digits. Only defined for valid ids.

func (ZidN) IsValid added in v0.18.0

func (zid ZidN) IsValid() bool

IsValid determines if zettel id is a valid one, e.g. consists of max. 14 digits.

func (ZidN) String added in v0.18.0

func (zid ZidN) String() string

String converts the zettel identification to a string of 14 digits. Only defined for valid ids.

func (ZidN) ZettelID added in v0.18.0

func (zid ZidN) ZettelID() api.ZettelID

ZettelID return the zettel identification as a api.ZettelID.

Jump to

Keyboard shortcuts

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