Skip to main content

map.go

map.go - Overview

This file defines the ITable interface, which provides an abstraction for map-like data structures.

Detailed Documentation

ITable Interface

Purpose: Defines the interface for a table (map) data structure with basic operations.

type ITable[K comparable, V any] interface {
Put(key K, value V)
Get(key K) (V, bool)
Delete(key K)
Len() int
All(func(k K, obj V) bool)
}
  • Type Parameters:
    • K: The type of the key, which must be comparable.
    • V: The type of the value.

Put Function

Purpose: Inserts or updates a key-value pair in the table.

Put(key K, value V)
  • Parameters:
    • key (K): The key to insert or update.
    • value (V): The value associated with the key.
  • Returns: None.

Get Function

Purpose: Retrieves the value associated with a key from the table.

Get(key K) (V, bool)
  • Parameters:
    • key (K): The key to retrieve.
  • Returns:
    • V: The value associated with the key. If the key is not found, returns the zero value of type V.
    • bool: A boolean indicating whether the key was found in the table.

Delete Function

Purpose: Removes a key-value pair from the table.

Delete(key K)
  • Parameters:
    • key (K): The key to delete.
  • Returns: None.

Len Function

Purpose: Returns the number of elements in the table.

Len() int
  • Parameters: None
  • Returns:
    • int: The number of key-value pairs in the table.

All Function

Purpose: Iterates over all key-value pairs in the table and applies a given function.

All(func(k K, obj V) bool)
  • Parameters:
    • func(k K, obj V) bool: A function that takes a key (K) and a value (V) as input and returns a boolean. Iteration stops if the function returns false.
  • Returns: None.

Getting Started Relevance