Skip to main content

interface.go

interface.go - Overview

  1. Overview Defines the BaseLabels interface, which provides methods for working with a collection of labels.

  2. Detailed Documentation

BaseLabels Interface

  • Purpose: Defines an interface for interacting with a set of labels (key-value pairs). Each method provides a different way to access, manipulate, or represent the labels.

Len()

  • Purpose: Returns the number of labels.
  • Returns: int - The number of labels.

Swap(i, j int)

  • Purpose: Swaps the labels at indices i and j.
  • Parameters:
    • i int: The index of the first label.
    • j int: The index of the second label.
  • Returns: None

Less(i, j int) bool

  • Purpose: Compares the labels at indices i and j and returns true if the label at i is less than the label at j.
  • Parameters:
    • i int: The index of the first label.
    • j int: The index of the second label.
  • Returns: bool - True if the label at index i is less than the label at index j, false otherwise.

String()

  • Purpose: Returns a string representation of the labels.
  • Returns: string - The string representation of the labels.

Hash()

  • Purpose: Calculates and returns a hash value for the labels.
  • Returns: uint64 - The hash value of the labels.

HashForLabels(b []byte, names ...string) (uint64, []byte)

  • Purpose: Calculates a hash value for a subset of labels specified by names, using b as the initial byte slice for the hash.
  • Parameters:
    • b []byte: The initial byte slice for the hash calculation.
    • names ...string: The names of the labels to include in the hash.
  • Returns: (uint64, []byte) - The calculated hash value (uint64) and the updated byte slice (used internally for hashing).

Get(name string) string

  • Purpose: Retrieves the value of the label with the given name.
  • Parameters:
    • name string: The name of the label.
  • Returns: string - The value of the label, or an empty string if the label is not found.

Has(name string) bool

  • Purpose: Checks if a label with the given name exists.
  • Parameters:
    • name string: The name of the label.
  • Returns: bool - True if the label exists, false otherwise.

Map() map[string]string

  • Purpose: Returns a map containing all labels.
  • Returns: map[string]string - A map where the keys are label names and the values are label values.

Include in Getting Started: NO