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 ¶
- type Row
- func (r *Row) Copy() *Row
- func (r *Row) Count() int
- func (r *Row) Enabled() bool
- func (r *Row) Item(index int) interface{}
- func (r *Row) Items() []interface{}
- func (r *Row) Matches(index int, value interface{}) bool
- func (r *Row) SetItem(index int, value interface{}) error
- func (r *Row) String() string
- func (r *Row) ToggleRow(enabled bool)
- type Table
- func (t *Table) Add(items ...interface{}) error
- func (t *Table) AddRow(r *Row) error
- func (t *Table) CSV() string
- func (t *Table) Clear() error
- func (t *Table) ColumnToIndex(header string) int
- func (t *Table) Columns() int
- func (t *Table) Copy() *Table
- func (t *Table) Count() int
- func (t *Table) Disabled() int
- func (t *Table) Enabled() int
- func (t *Table) Headers() []string
- func (t *Table) Insert(index int, items ...interface{}) error
- func (t *Table) InsertRow(index int, r *Row) error
- func (t *Table) Item(header string, index int) interface{}
- func (t *Table) Matches(header string, index int, value interface{}) bool
- func (t *Table) RemoveRow(index int)
- func (t *Table) Row(header string, item interface{}) (int, *Row)
- func (t *Table) RowByIndex(index int) *Row
- func (t *Table) Rows() int
- func (t *Table) Same(nt *Table) bool
- func (t *Table) SetHeader(oldHeader, newHeader string) error
- func (t *Table) SetItem(header string, index int, value interface{}) error
- func (t *Table) SortByColumn(header string, less func(interface{}, interface{}) bool) error
- func (t *Table) SortByRow(less func(*Row, *Row) bool) error
- func (t *Table) String() string
- func (t *Table) Toggle(index int, enabled bool) error
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 (*Row) Copy ¶ added in v0.4.0
Copy makes a complete and separate copy of the row. If the row to copy is nil, it returns nil.
func (*Row) Item ¶
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 ¶
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.
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 ¶
New creates a new table. headers denotes the name of each column. Each header must be unique and not empty.
func (*Table) CSV ¶ added in v0.4.0
CSV returns a representation of the table as rows of comma-separated values, with each row delineated by \r\n newlines.
func (*Table) Clear ¶
Clear erases the rows in the table but leaves the column headers and column types.
func (*Table) ColumnToIndex ¶
ColumnToIndex returns the index of the column by header, or -1 if not found.
func (*Table) Copy ¶ added in v0.4.0
Copy makes an exact and separate copy of the table. If the table to copy is nil, it returns nil.
func (*Table) Count ¶
Count returns the number of items in the table, or -1 on error. This includes all items, regardless of enabled status.
func (*Table) Insert ¶
Insert creates a new row with the items and inserts it into the table at the specified index.
func (*Table) Item ¶
Item returns the item at the specified coordinates, or nil if there is no item at the coordinates.
func (*Table) Matches ¶
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) 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
RowByIndex returns the Row at the specified index, or nil if not found or error.
func (*Table) Rows ¶
Rows returns the number of rows in the table, or -1 on error. This includes all rows, regardless of enabled status.
func (*Table) SortByColumn ¶ added in v0.4.0
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
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.