Skip to main content

Mojo struct

CountTuple

struct CountTuple[V: ExplicitlyCopyable & Movable & Hashable & EqualityComparable]

A tuple representing a value and its count in a Counter.

Parameters

Implemented traits

AnyType, Copyable, ExplicitlyCopyable, Movable, UnknownDestructibility

Aliases

__copyinit__is_trivial

alias __copyinit__is_trivial = False

__del__is_trivial

alias __del__is_trivial = get_witness(V, stdlib::builtin::anytype::AnyType, __del__is_trivial)

__moveinit__is_trivial

alias __moveinit__is_trivial = get_witness(V, stdlib::builtin::value::Movable, __moveinit__is_trivial)

Methods

__init__

__init__(out self, value: V, count: UInt)

Create a new CountTuple.

Args:

  • value (V): The value in the Counter.
  • count (UInt): The count of the value in the Counter.

__copyinit__

__copyinit__(out self, existing: Self)

Creates a copy of the tuple.

Args:

  • existing (Self): The tuple to copy.

__getitem__

__getitem__(self, idx: Int) -> Variant[V, Int]

Get an element in the tuple.

Args:

  • idx (Int): The element to return.

Returns:

Variant: The value if idx is 0 and the count if idx is 1.

__lt__

__lt__(self, other: Self) -> Bool

Compare two CountTuples by count, then by value.

Args:

  • other (Self): The other CountTuple to compare to.

Returns:

Bool: True if this CountTuple is less than the other, False otherwise.

__eq__

__eq__(self, other: Self) -> Bool

Compare two CountTuples for equality.

Args:

  • other (Self): The other CountTuple to compare to.

Returns:

Bool: True if the two CountTuples are equal, False otherwise.

Was this page helpful?