rws

package
v0.0.0-...-d89fc40 Latest Latest
Warning

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

Go to latest
Published: Nov 4, 2024 License: MIT Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Map

type Map[T comparable, U any] struct {
	// contains filtered or unexported fields
}

Map is a thread-safe map. To create an empty map, use the `sm := new(rws.Map[T, U])` constructor.

func (*Map[T, U]) Copy

func (sm *Map[T, U]) Copy() *Map[T, U]

Copy is a method that returns a copy of the Map.

Returns:

  • *Map[T, U]: A copy of the Map. An empty Map if the receiver is nil.

func (*Map[T, U]) Delete

func (sm *Map[T, U]) Delete(key T)

Delete removes a key from the map. Does nothing if the key does not exist in the map.

Parameters:

  • key: The key to remove.

func (*Map[T, U]) Entry

func (sm *Map[T, U]) Entry() iter.Seq2[T, U]

Entry is a method that returns an iterator over the entries in the Map.

Returns:

  • iter.Seq2[T, U]: An iterator over the entries in the Map. Never returns nil.

func (*Map[T, U]) Get

func (sm *Map[T, U]) Get(key T) (U, bool)

Get retrieves a value from the map.

Parameters:

  • key: The key to retrieve the value.

Returns:

  • U: The value associated with the key.
  • bool: A boolean indicating if the key exists in the map.

func (*Map[T, U]) GetMap

func (sm *Map[T, U]) GetMap() map[T]U

GetMap returns the underlying map.

Returns:

  • map[T]U: The underlying map. Nil if the receiver is nil.

func (*Map[T, U]) Len

func (sm *Map[T, U]) Len() int

Len returns the number of elements in the map.

Returns:

  • int: The number of elements in the map. 0 if the receiver is nil.

func (*Map[T, U]) Reset

func (sm *Map[T, U]) Reset()

Reset removes all elements from the map.

func (*Map[T, U]) Set

func (sm *Map[T, U]) Set(key T, val U) error

Set sets a value in the map. Does nothing if the receiver is nil.

Parameters:

  • key: The key to set the value.
  • val: The value to set.

Returns:

  • error: An error if the receiver is nil.

type Slice

type Slice[T any] struct {
	// contains filtered or unexported fields
}

Slice is a slice that can be read and written safely. It must be created using the `s := new(rws.Slice[T])` constructor.

func (*Slice[T]) Append

func (s *Slice[T]) Append(slice ...T) error

Append appends a slice to the Slice.

Parameters:

  • slice: The slice to append.

Returns:

  • error: Nil if the receiver is nil.

Errors:

  • errors.ErrNilReceiver: If the receiver is nil.

func (*Slice[T]) Copy

func (s *Slice[T]) Copy() *Slice[T]

Copy returns a deep copy of the slice. If the receiver is nil, a new empty slice is returned.

Returns:

  • *Slice[T]: The copy of the slice. Never returns nil.

func (*Slice[T]) Free

func (s *Slice[T]) Free()

Free releases any resources associated with the Slice.

func (*Slice[T]) Size

func (s *Slice[T]) Size() int

Size returns the number of elements in the Slice.

Returns:

  • int: The number of elements in the Slice. 0 when the receiver is nil.

func (*Slice[T]) Slice

func (s *Slice[T]) Slice() []T

Slice returns a copy of the elements in the Slice.

Returns:

  • []T: A copy of the elements in the Slice. Nil if the receiver is nil.

type Table

type Table[T any] struct {
	// contains filtered or unexported fields
}

Table is a boundless table. This means that any operation done to out-of-bounds cells will not cause any error. The table is safe for concurrent use.

func NewTable

func NewTable[T any](width, height int) (*Table[T], error)

NewTable creates a new Table with a width and height.

Parameters:

  • width: The width of the table.
  • height: The height of the table.

Returns:

  • *Table: The new Table.
  • error: If the table could not be created.

Errors:

  • errors.BadParameterError: If width or height is negative.

func (*Table[T]) CellAt

func (t *Table[T]) CellAt(x, y int) T

CellAt returns the cell at the specified position.

Parameters:

  • x: The x position of the cell.
  • y: The y position of the cell.

Returns:

  • T: The cell at the specified position. The zero value if the receiver is nil or the position is out of bounds.

func (*Table[T]) Free

func (t *Table[T]) Free()

Free releases any resources associated with the Table.

func (*Table[T]) Height

func (t *Table[T]) Height() int

Height returns the height of the table.

Returns:

  • int: The height of the table. 0 if the receiver is nil.

func (*Table[T]) ResizeHeight

func (t *Table[T]) ResizeHeight(new_height int) error

ResizeHeight resizes the height of the table. The height is not resized if the receiver is nil or the new height is the same as the current height.

Parameters:

  • new_height: The new height of the table.

Returns:

  • error: If the table could not be resized.

Errors:

  • gers.BadParameterError: If new_height is negative.

func (*Table[T]) ResizeWidth

func (t *Table[T]) ResizeWidth(new_width int) error

ResizeWidth resizes the width of the table. The width is not resized if the receiver is nil or the new width is the same as the current width.

Parameters:

  • new_width: The new width of the table.

Returns:

  • error: If the table could not be resized.

Errors:

  • gers.BadParameterError: If new_width is negative.

func (*Table[T]) Row

func (t *Table[T]) Row() iter.Seq2[int, []T]

Row returns an iterator over the rows in the table.

Returns:

  • iter.Seq2[int, []T]: An iterator over the rows in the table. Never returns nil.

func (*Table[T]) SetCellAt

func (t *Table[T]) SetCellAt(cell T, x, y int)

SetCellAt sets the cell at the specified position. The cell is not set if the receiver is nil or the position is out of bounds.

Parameters:

  • cell: The cell to set.
  • x: The x position of the cell.
  • y: The y position of the cell.

func (*Table[T]) Width

func (t *Table[T]) Width() int

Width returns the width of the table.

Returns:

  • int: The width of the table. 0 if the receiver is nil.

type Var

type Var[T any] struct {
	// contains filtered or unexported fields
}

Var is a variable that can be read and written safely. To create a Var with the zero value, use the `v := new(rws.Var[T])` constructor.

func New

func New[T any](data T) *Var[T]

New creates a new Var.

Parameters:

  • data: The initial value of the variable.

Returns:

  • *Var[T]: The new Var. Never returns nil.

func (*Var[T]) Copy

func (s *Var[T]) Copy() *Var[T]

Copy returns a copy of the Var.

Returns:

  • *Var[T]: A copy of the Var. Never returns nil.

If the receiver is nil, a new Var is returned.

func (*Var[T]) Edit

func (s *Var[T]) Edit(fn func(elem *T)) error

Edit edits the value of the variable. Does nothing if the function is nil.

Parameters:

  • fn: The function to edit the value.

Returns:

  • error: An error if the receiver is nil.

func (*Var[T]) Get

func (s *Var[T]) Get() (T, error)

Get returns the value of the variable.

Returns:

  • T: The value.
  • error: An error if the receiver is nil.

Errors:

  • common.ErrNilReceiver: If the receiver is nil.

func (*Var[T]) MustGet

func (s *Var[T]) MustGet() T

MustGet returns the value of the variable.

Returns:

  • T: The value. The zero value if the receiver is nil.

func (*Var[T]) Set

func (s *Var[T]) Set(data T) error

Set sets the value of the variable.

Parameters:

  • data: The value to set.

Returns:

  • error: An error if the receiver is nil.

Jump to

Keyboard shortcuts

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