columnsorter

package
v0.0.0-...-9d3c4bc Latest Latest
Warning

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

Go to latest
Published: Nov 1, 2019 License: Apache-2.0 Imports: 2 Imported by: 0

Documentation

Overview

Package columnsorter performs toposort of column names. It is used to compute the exhausitve list of columns in a table, when not all the row may have the same set of columns.

Thread compatible.

Legal call sequence: New AddColumns* Sort (Columns|Index)*

Example
package main

import (
	"fmt"

	"github.com/grailbio/gql/columnsorter"
	"github.com/grailbio/gql/symbol"
)

func main() {
	s := columnsorter.New()
	s.AddColumns([]symbol.ID{10, 11, 12})
	s.AddColumns([]symbol.ID{12, 13})
	s.AddColumns([]symbol.ID{11, 20, 12})
	s.Sort()
	fmt.Println(s.Columns())
	fmt.Println(s.Index(20))
}
Output:

[10 11 20 12 13]
2

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type T

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

T is the main sorter object. Use New() to create the sorter.

func New

func New() *T

New creates a new sorter.

func (*T) AddColumns

func (t *T) AddColumns(colNames []symbol.ID)

AddColumns adds a sorted list of columns that appear in a row. One column can appear multiple times across AddColumn calls.

REQUIRES: Sort has not been called

func (*T) Columns

func (t *T) Columns() []symbol.ID

Columns returns a toposorted list of columns.

REQUIRES: Sort has been called

func (*T) Index

func (t *T) Index(name symbol.ID) int

Index returns the index of the given column in the toposorted list. The first column has index zero.

REQUIRES: Sort has been called

func (*T) Sort

func (t *T) Sort()

Sort the columns added so far, so that the resulting list is compatible with the column orders specified in all preceding AddColumns calls. After the Sort call, no AddColumn can be called.

Jump to

Keyboard shortcuts

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