objecttables

package module
v0.0.0-...-1d82421 Latest Latest
Warning

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

Go to latest
Published: Aug 13, 2026 License: AGPL-3.0 Imports: 11 Imported by: 0

README

Mayfair object tables

This library gives 2D tables with as elements go struct types that are implement the FactI[K comparable] interface. The tables then can be combined in a RETE network to perform SQL like joins on the tables. The result table fullfills all the conditions (about one fact or binary conditions about two facts). These functions are used in the mayfair distributed database project.

Each fact that is stored in an element of a table is identified by its data sort name, e.g. "Person". In the fact itself the datasort is identified by its integer table index field Tix(). A one column object table stores instances of one data sort and corresponds somewhat with a SQL table in which each object's corresponds with a column in the SQL table.

the libraries can be tested by the command go test ./... the makefile is used to generate the stringer interface on the JoinType enum type.

The makefile has the following targets

  • make : generate the stringer files and build the code
  • make test : perform all tests

Documentation

Overview

* * Frank Willem Mulder * __________________ * * Copyright 2026 Frank Willem Mulder. All rights reserved. * Use of this source code is governed license that can be found in the LICENSE file.

* * Frank Willem Mulder * __________________ * * Copyright 2026 Frank Willem Mulder. All rights reserved. * Use of this source code is governed license that can be found in the LICENSE file.

* * Frank Willem Mulder * __________________ * * Copyright 2026 Frank Willem Mulder. All rights reserved. * Use of this source code is governed license that can be found in the LICENSE file.

* * Frank Willem Mulder * __________________ * * Copyright 2026 Frank Willem Mulder. All rights reserved. * Use of this source code is governed license that can be found in the LICENSE file.

* * Frank Willem Mulder * __________________ * * Copyright 2026 Frank Willem Mulder. All rights reserved. * Use of this source code is governed license that can be found in the LICENSE file.

* * Frank Willem Mulder * __________________ * * Copyright 2026 Frank Willem Mulder. All rights reserved. * Use of this source code is governed license that can be found in the LICENSE file.

* * Frank Willem Mulder * __________________ * * Copyright 2026 Frank Willem Mulder. All rights reserved. * Use of this source code is governed license that can be found in the LICENSE file.

* * Frank Willem Mulder * __________________ * * Copyright 2026 Frank Willem Mulder. All rights reserved. * Use of this source code is governed license that can be found in the LICENSE file.

* * Frank Willem Mulder * __________________ * * Copyright 2026 Frank Willem Mulder. All rights reserved. * Use of this source code is governed license that can be found in the LICENSE file.

* * Frank Willem Mulder * __________________ * * Copyright 2026 Frank Willem Mulder. All rights reserved. * Use of this source code is governed license that can be found in the LICENSE file.

* * Frank Willem Mulder * __________________ * * Copyright 2026 Frank Willem Mulder. All rights reserved. * Use of this source code is governed license that can be found in the LICENSE file.

* * Frank Willem Mulder * __________________ * * Copyright 2026 Frank Willem Mulder. All rights reserved. * Use of this source code is governed license that can be found in the LICENSE file.

Index

Constants

View Source
const TIX = "Tixx"

Variables

This section is empty.

Functions

func CalcKeys

func CalcKeys[K comparable](u any) []K

func ClearTableIdx

func ClearTableIdx()

func GetClass

func GetClass(bs []byte) string

GetClass get the table name from a json byte string

func GetTableIdx

func GetTableIdx(table string) (int, bool)

func GetTableName

func GetTableName(idx int) (string, bool)

func MkFacts

func MkFacts() ([]*person, []*flight, []*airport, []*country)

func ReadTable

func ReadTable(name string) ([][]string, error)

func StoreTableIdx

func StoreTableIdx(table string) int

Types

type AlphaNode

type AlphaNode[K comparable] struct {
	// contains filtered or unexported fields
}

func NewAlphaNode

func NewAlphaNode[K comparable](no int, tix int, preds []Pred[FactI[K]]) *AlphaNode[K]

func (*AlphaNode[K]) AddFacts

func (an *AlphaNode[K]) AddFacts(facts []ut.Optional[FactI[K]])

func (*AlphaNode[K]) AddMods

func (an *AlphaNode[K]) AddMods(mods []FactMod[K])

func (*AlphaNode[K]) Clear

func (an *AlphaNode[K]) Clear()

func (*AlphaNode[K]) GetTable

func (an *AlphaNode[K]) GetTable() TableI[FactI[K]]

func (*AlphaNode[K]) Propagate

func (an *AlphaNode[K]) Propagate()

func (*AlphaNode[K]) SetChild

func (an *AlphaNode[K]) SetChild(child NodeI[K])

func (*AlphaNode[K]) String

func (an *AlphaNode[K]) String() string

type BetaNode

type BetaNode[K comparable] struct {
	// contains filtered or unexported fields
}

func NewBetaNode

func NewBetaNode[K comparable](no int, joinType JoinType, left NodeI[K], right NodeI[K], preds []Bip[FactI[K]]) *BetaNode[K]

func (*BetaNode[K]) Clear

func (bn *BetaNode[K]) Clear()

func (*BetaNode[K]) GetTable

func (bn *BetaNode[K]) GetTable() TableI[FactI[K]]

func (*BetaNode[K]) Propagate

func (bn *BetaNode[K]) Propagate()

func (*BetaNode[K]) SetChild

func (bn *BetaNode[K]) SetChild(child NodeI[K])

func (*BetaNode[K]) String

func (bn *BetaNode[K]) String() string

type Bip

type Bip[V comparable] struct {
	No             int
	Test           func(ut.Optional[V], ut.Optional[V]) bool
	Table1, Table2 int
}

func NewBiPred

func NewBiPred[V comparable](no, t1, t2 int, test func(v1 ut.Optional[V], v2 ut.Optional[V]) bool) Bip[V]

func (*Bip[V]) GetTuple

func (b *Bip[V]) GetTuple() ut.Tuple

type Fact

type Fact[K comparable] struct {
	Tablex string `json:"table-name"`
	Tixx   int    `json:"-"`
}

func NewFact

func NewFact[K comparable](table string, tix int) Fact[K]

func (*Fact[K]) Equals

func (f *Fact[K]) Equals(o FactI[K]) bool

func (*Fact[K]) FromBytes

func (f *Fact[K]) FromBytes(buf []byte) FactI[K]

func (*Fact[K]) Keys

func (f *Fact[K]) Keys() []K

func (*Fact[K]) SetTix

func (f *Fact[K]) SetTix(t int)

func (*Fact[K]) Table

func (f *Fact[K]) Table() string

func (*Fact[K]) Tix

func (f *Fact[K]) Tix() int

func (*Fact[K]) ToBytes

func (f *Fact[K]) ToBytes() []byte

type FactI

type FactI[K comparable] interface {
	Keys() []K
	Tix() int
	Table() string
	Equals(o FactI[K]) bool
	ToBytes() []byte
	FromBytes([]byte) FactI[K]
}

type FactMod

type FactMod[K comparable] struct {
	Trans TransactionType
	Table string
	Fact  FactI[K]
	Tix   int
}

func NewFactMod

func NewFactMod[K comparable](trans TransactionType, table string, fact FactI[K]) FactMod[K]

type JoinType

type JoinType int
const (
	INNERJOIN JoinType = iota
	CROSSJOIN
	JOIN
	NATURALJOIN
	LEFTJOIN
	RIGHTJOIN
	FULLJOIN
)

func (JoinType) String

func (i JoinType) String() string

type NodeI

type NodeI[K comparable] interface {
	// GetTable  the facts of an alpha node and the joined facts of a beta node are stored in a Table of objects */
	GetTable() TableI[FactI[K]]

	// SetChild   the nodes are part of a binary tree network, so each alpha and beta node has one child and
	SetChild(NodeI[K])

	// Propagate propagate the facts of the alpha nodes through the rete network */
	Propagate()
	// Clear  all data to make network ready for new calculations */
	Clear()
	String() string
	// contains filtered or unexported methods
}

type OrderBy

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

func NewOrderBy

func NewOrderBy(tix, col int, field string, dir SortDir) OrderBy

type Pred

type Pred[V comparable] struct {
	No    int
	Table int
	Test  func(f ut.Optional[V]) bool
}

func NewPred

func NewPred[V comparable](no, table int, test func(f ut.Optional[V]) bool) Pred[V]

type ReteNetwork

type ReteNetwork[K comparable] struct {
	Modified     bool
	NoIterations uint64
	// contains filtered or unexported fields
}

func NewReteNetwork

func NewReteNetwork[K comparable](as []*AlphaNode[K], bs []*BetaNode[K]) *ReteNetwork[K]

func (*ReteNetwork[K]) AddMods

func (r *ReteNetwork[K]) AddMods(ms []FactMod[K])

func (*ReteNetwork[K]) Clear

func (r *ReteNetwork[K]) Clear()

func (*ReteNetwork[K]) HasTable

func (r *ReteNetwork[K]) HasTable(tix int) bool

func (*ReteNetwork[K]) Propagate

func (r *ReteNetwork[K]) Propagate()

type Rowi

type Rowi[V comparable] interface {
	IsValue() bool
	Values() []ut.Optional[V]
	ValuesQ(int) []ut.Optional[V]
	Add(optional ut.Optional[V])
	HasTable(int) bool
	Tables() ([]int, bool)

	String() string
	Equals(rowi Rowi[V]) bool
	SetTables(tables []int)
	Update(i int, of ut.Optional[V])
	Delete(i int)
	// contains filtered or unexported methods
}

func NewNullRow

func NewNullRow[V comparable](n int) Rowi[V]

func NewRow

func NewRow[V comparable]() Rowi[V]

func NewRowF1

func NewRowF1[V comparable](v ut.Optional[V]) Rowi[V]

func NewRowFN

func NewRowFN[V comparable](vs []ut.Optional[V]) Rowi[V]

type Select

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

func NewSelect

func NewSelect(table int, field, alias string, sel Selection) Select

type Selection

type Selection int
const (
	ALL_TABLES Selection = iota
	SELECT_TABLES
	SELECT_VALUES
	SELECT_UNKNOWN
)

func (Selection) String

func (i Selection) String() string

type SortDir

type SortDir int
const (
	ASC SortDir = iota
	DESC
	ORDER_UNKNOWN
)

type Table

type Table[V comparable] struct {
	// contains filtered or unexported fields
}

func MakeTable

func MakeTable(name string) (*Table[any], error)

func NewTable

func NewTable[V comparable]() *Table[V]

func NewTablePs

func NewTablePs[V comparable](ts []int, cs []string) *Table[V]

func (*Table[V]) AddRow1

func (t *Table[V]) AddRow1(r Rowi[V])

func (*Table[V]) AddRowF1

func (t *Table[V]) AddRowF1(v ut.Optional[V])

func (*Table[V]) AddRowFN

func (t *Table[V]) AddRowFN(vs []ut.Optional[V])

func (*Table[V]) AddRowsFN

func (t *Table[V]) AddRowsFN(vs []ut.Optional[V])

func (*Table[V]) Clear

func (t *Table[V]) Clear()

func (*Table[any]) CmpCsv

func (t *Table[any]) CmpCsv(csvs [][]string) bool

func (*Table[V]) ColumnCount

func (t *Table[V]) ColumnCount() int

func (*Table[V]) Columns

func (t *Table[V]) Columns() []string

func (*Table[V]) CrossJoin

func (t *Table[V]) CrossJoin(o TableI[V]) TableI[V]

func (*Table[V]) DeleteF1

func (t *Table[V]) DeleteF1(of ut.Optional[V])

func (*Table[V]) FullJoin

func (t *Table[V]) FullJoin(o TableI[V], preds []Bip[V]) TableI[V]

FullJoin performs full outer join

func (*Table[V]) GetValues

func (t *Table[V]) GetValues() []ut.Optional[V]

func (*Table[V]) InnerJoin

func (t *Table[V]) InnerJoin(o TableI[V], preds []Bip[V]) TableI[V]

func (*Table[V]) IsEmpty

func (t *Table[V]) IsEmpty() bool

func (*Table[V]) IsValue

func (t *Table[V]) IsValue() bool

func (*Table[V]) LeftJoin

func (t *Table[V]) LeftJoin(o TableI[V], preds []Bip[V]) TableI[V]

LeftJoin performs left outer join

func (*Table[V]) NaturalJoin

func (t *Table[V]) NaturalJoin(o TableI[V]) TableI[V]

func (*Table[V]) OrderBy

func (t *Table[V]) OrderBy(obs []OrderBy)

func (*Table[V]) RightJoin

func (t *Table[V]) RightJoin(o TableI[V], preds []Bip[V]) TableI[V]

RightJoin performs right outer join

func (*Table[V]) RowCount

func (t *Table[V]) RowCount() int

func (*Table[V]) Rows

func (t *Table[V]) Rows() []Rowi[V]

func (*Table[V]) SameTables

func (t *Table[V]) SameTables(o TableI[V]) bool

func (*Table[V]) Selection

func (t *Table[V]) Selection(selections []Select) TableI[any]

func (*Table[V]) String

func (t *Table[V]) String() string

func (*Table[V]) TableCount

func (t *Table[V]) TableCount() int

func (*Table[V]) Tables

func (t *Table[V]) Tables() []int

func (*Table[V]) Union

func (t *Table[V]) Union(o TableI[V]) TableI[V]

Union merges the rows and columns of two tables (normally a SQL union requires the columns to be equal, but not in this function)

func (*Table[V]) UpdateRowF1

func (t *Table[V]) UpdateRowF1(of ut.Optional[V])

type TableI

type TableI[V comparable] interface {
	IsValue() bool
	Rows() []Rowi[V]
	AddRow1(Rowi[V])
	AddRowF1(v ut.Optional[V])
	UpdateRowF1(of ut.Optional[V])
	DeleteF1(of ut.Optional[V])
	AddRowFN(v []ut.Optional[V])
	AddRowsFN(v []ut.Optional[V])

	RowCount() int
	TableCount() int
	ColumnCount() int
	Clear()
	Tables() []int
	Columns() []string
	SameTables(TableI[V]) bool
	InnerJoin(TableI[V], []Bip[V]) TableI[V]
	NaturalJoin(TableI[V]) TableI[V]
	CrossJoin(TableI[V]) TableI[V]
	LeftJoin(TableI[V], []Bip[V]) TableI[V]
	RightJoin(TableI[V], []Bip[V]) TableI[V]
	FullJoin(TableI[V], []Bip[V]) TableI[V]
	Union(TableI[V]) TableI[V]
	IsEmpty() bool
	GetValues() []ut.Optional[V]
	Selection([]Select) TableI[any]
	OrderBy([]OrderBy)
}

TableI for the natural join operation on two tables the value type V needs to be comparable

type TransactionType

type TransactionType int
const (
	UPDATE TransactionType = iota
	INSERT
	DELETE
	ERROR
	NONE
)

func (TransactionType) String

func (i TransactionType) String() string

Jump to

Keyboard shortcuts

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