id

package
v0.17.0 Latest Latest
Warning

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

Go to latest
Published: Mar 4, 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 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.

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 map[Zid]struct{}

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) 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) Copy added in v0.14.0

func (s Set) Copy(other Set) Set

Copy adds all member from the other set.

func (Set) CopySlice added in v0.14.0

func (s Set) CopySlice(sl Slice) Set

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

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) 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) Remove

func (s Set) Remove(zid Zid) Set

Remove the identifier from the set.

func (Set) Sorted

func (s Set) Sorted() Slice

Sorted returns the set as a 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 map.

func (Set) Substract added in v0.14.0

func (s Set) Substract(other Set)

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

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) Sort

func (zs Slice) Sort()

Sort a slice of Zids.

func (Slice) String

func (zs Slice) String() string

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.

Jump to

Keyboard shortcuts

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