textindex

package module
v1.0.2 Latest Latest
Warning

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

Go to latest
Published: Mar 19, 2020 License: MPL-2.0 Imports: 1 Imported by: 0

README

textindex

pipeline status coverage report godoc

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.

CLI

A command line interface exists in cmd/textindex, to generate indexes via script.

Installation should be as simple as...

go install gitlab.com/etomyutikos/textindex/cmd/textindex

Usage can be seen with...

textindex --help

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

func Between(previous, next string) string

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

func (g Generator) Between(previous, next string) string

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

Directories

Path Synopsis
cmd
run

Jump to

Keyboard shortcuts

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