htable

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: May 1, 2021 License: MIT Imports: 4 Imported by: 0

Documentation

Overview

Package htable is a data structure of rows and columns, with each row having the same number of items and each column holding the same type of data. The tables provide easy, fast construction and lookup of uniform lists. Following the go convention, all data within a column must have the same static type.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Row

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

Row holds all the data for each row in the table.

func NewRow

func NewRow(items ...interface{}) *Row

NewRow creates a new row with the given items.

func (*Row) Copy added in v0.4.0

func (r *Row) Copy() *Row

Copy makes a complete and separate copy of the row. If the row to copy is nil, it returns nil.

func (*Row) Count

func (r *Row) Count() int

Count returns the number of items in the row, or -1 on error.

func (*Row) Enabled added in v0.4.0

func (r *Row) Enabled() bool

Enabled returns true if the row is enabled, otherwise false.

func (*Row) Item

func (r *Row) Item(index int) interface{}

Item returns the item's value at the specified index in this row, or nil if not found or error.

func (*Row) Items added in v0.4.0

func (r *Row) Items() []interface{}

Items returns a copy of the items in the row.

func (*Row) Matches

func (r *Row) Matches(index int, value interface{}) bool

Matches returns true if the value matches the item in the specified column or false if there is no match. Matching can occur on disabled rows.

func (*Row) SetItem

func (r *Row) SetItem(index int, value interface{}) error

SetItem changes the value of the item in the specified column index.

func (*Row) String

func (r *Row) String() string

String returns a formatted list of the items in the row.

func (*Row) ToggleRow added in v0.4.0

func (r *Row) ToggleRow(enabled bool)

ToggleRow sets the row as either enabled or disabled.

type Table

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

Table is the main type in this package. It holds all the rows of data.

func New

func New(headers ...string) (*Table, error)

New creates a new table. headers denotes the name of each column. Each header must be unique and not empty.

func (*Table) Add

func (t *Table) Add(items ...interface{}) error

Add creates a new row with the items and adds it to the end of the table.

func (*Table) AddRow

func (t *Table) AddRow(r *Row) error

AddRow adds the row to the end of the table.

func (*Table) CSV added in v0.4.0

func (t *Table) CSV() string

CSV returns a representation of the table as rows of comma-separated values, with each row delineated by \r\n newlines.

func (*Table) Clear

func (t *Table) Clear() error

Clear erases the rows in the table but leaves the column headers and column types.

func (*Table) ColumnToIndex

func (t *Table) ColumnToIndex(header string) int

ColumnToIndex returns the index of the column by header, or -1 if not found.

func (*Table) Columns

func (t *Table) Columns() int

Columns returns the number of columns in the table, or -1 on error.

func (*Table) Copy added in v0.4.0

func (t *Table) Copy() *Table

Copy makes an exact and separate copy of the table. If the table to copy is nil, it returns nil.

func (*Table) Count

func (t *Table) Count() int

Count returns the number of items in the table, or -1 on error. This includes all items, regardless of enabled status.

func (*Table) Disabled

func (t *Table) Disabled() int

Disabled returns the number of disabled rows in the table, or -1 on error.

func (*Table) Enabled

func (t *Table) Enabled() int

Enabled returns the number of enabled rows in the table, or -1 on error.

func (*Table) Headers

func (t *Table) Headers() []string

Headers returns a copy of the table's column headers.

func (*Table) Insert

func (t *Table) Insert(index int, items ...interface{}) error

Insert creates a new row with the items and inserts it into the table at the specified index.

func (*Table) InsertRow

func (t *Table) InsertRow(index int, r *Row) error

InsertRow inserts the row into the table at the specified index.

func (*Table) Item

func (t *Table) Item(header string, index int) interface{}

Item returns the item at the specified coordinates, or nil if there is no item at the coordinates.

func (*Table) Matches

func (t *Table) Matches(header string, index int, value interface{}) bool

Matches returns true if the value matches the item at the specified coordinates or false if there is no match. Matching can occur on disabled rows.

func (*Table) RemoveRow

func (t *Table) RemoveRow(index int)

RemoveRow deletes the row at the index from the table.

func (*Table) Row

func (t *Table) Row(header string, item interface{}) (int, *Row)

Row returns the index and Row of the first enabled row that contains the item in the specified column, or -1 and nil if not found or error.

func (*Table) RowByIndex added in v0.4.0

func (t *Table) RowByIndex(index int) *Row

RowByIndex returns the Row at the specified index, or nil if not found or error.

func (*Table) Rows

func (t *Table) Rows() int

Rows returns the number of rows in the table, or -1 on error. This includes all rows, regardless of enabled status.

func (*Table) Same

func (t *Table) Same(nt *Table) bool

Same checks whether or not the tables point to the same memory.

func (*Table) SetHeader

func (t *Table) SetHeader(oldHeader, newHeader string) error

SetHeader changes the specified column's header.

func (*Table) SetItem

func (t *Table) SetItem(header string, index int, value interface{}) error

SetItem changes the value of the item at the specified coordinates.

func (*Table) SortByColumn added in v0.4.0

func (t *Table) SortByColumn(header string, less func(interface{}, interface{}) bool) error

SortByColumn sorts the table on the specified column. The comparison function less is given the values of two different items in a column and should return true only if the left item should be sorted before the right item.

func (*Table) SortByRow added in v0.4.0

func (t *Table) SortByRow(less func(*Row, *Row) bool) error

SortByRow sorts the table by rows. The comparison function less is given pointers to two Row objects and should return true only if the left row should be sorted before the right row.

func (*Table) String

func (t *Table) String() string

String returns a formatted list of the items in the table, row by row.

func (*Table) Toggle

func (t *Table) Toggle(index int, enabled bool) error

Toggle sets the row at the specified index to either be checked or skipped during table lookups (like Row and Count).

Jump to

Keyboard shortcuts

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