Documentation ¶
Overview ¶
Package textindex implements a method for generating string indexes for sortable lists.
Utilizing the (theoretically) infinite precision of strings, we can create indexes that allow for arbitrary list ordering without having to update all subsequent items in the list.
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Between ¶
Between generates a new index between the given values using the default character set.
Example ¶
package main import ( "fmt" "gitlab.com/etomyutikos/textindex" ) func main() { fmt.Println(textindex.Between("00z07", "00z09")) }
Output: 00z08
Example (Decrement) ¶
package main import ( "fmt" "gitlab.com/etomyutikos/textindex" ) func main() { fmt.Println(textindex.Between("", "00b070z")) }
Output: 00b070y
Example (DecrementAtLimit) ¶
package main import ( "fmt" "gitlab.com/etomyutikos/textindex" ) func main() { fmt.Println(textindex.Between("", "0600301")) }
Output: 0600300i
Example (FirstItem) ¶
package main import ( "fmt" "gitlab.com/etomyutikos/textindex" ) func main() { fmt.Println(textindex.Between("", "")) }
Output: 0i
Example (Increment) ¶
package main import ( "fmt" "gitlab.com/etomyutikos/textindex" ) func main() { fmt.Println(textindex.Between("0o0p06", "")) }
Output: 0o0p07
Example (IncrementAtLimit) ¶
package main import ( "fmt" "gitlab.com/etomyutikos/textindex" ) func main() { fmt.Println(textindex.Between("0h040z", "")) }
Output: 0h040z0i
Example (NoGap) ¶
package main import ( "fmt" "gitlab.com/etomyutikos/textindex" ) func main() { fmt.Println(textindex.Between("0i0n0r", "0i0n0s")) }
Output: 0i0n0r0i
Types ¶
type Generator ¶
type Generator struct {
CharSet string
}
Generator encapsulates a character set for configurability and reusability. It also enables use as a mockable dependency.
func (Generator) Between ¶
Between generates a new index between the given values using the Generator. If no character set has been set, the default character set will be used.
Example ¶
package main import ( "fmt" "gitlab.com/etomyutikos/textindex" ) func main() { var g textindex.Generator fmt.Println(g.Between("0f00r03", "0f00r05")) }
Output: 0f00r04
Example (AlternativeCharSet) ¶
package main import ( "fmt" "gitlab.com/etomyutikos/textindex" ) func main() { g := textindex.Generator{ CharSet: "ABCDEFGHIJKLMNOPQRSTUVWXYZ", } fmt.Println(g.Between("ANAB", "ANAC")) }
Output: ANABAN
Click to show internal directories.
Click to hide internal directories.