Skip to content

Adt 2D Optimized

Documentation for std-library/ksp/data-structures/imports/adt-2d-optimized.ksp

Import

import "_IVLS/std-library/ksp/data-structures/imports/adt-2d-optimized.ksp"

API

Macros

Name Description
adt.2DListFunctions(#name#) Generates all operational functions for a 2D list instance.
adt.2DQueueFunctions(#name#) Generates all operational functions for a 2D queue instance.
adt.2DStackFunctions(#name#) Generates all operational functions for a 2D stack instance.
adt.Create2DList(#name#, #row1#, #row2#) Constructs a 2D integer list with random access support.
adt.Create2DQueue(#name#, #row#, #size#) Constructs a 2D integer queue with ring buffer storage per row.
adt.Create2DStack(#name#, #row#, #size#) Constructs a 2D integer stack.

Functions

Name Description
#name#.append.fast(row, element) Inserts element at end of row without capacity checking.
#name#.clear(row) Resets a row in the queue to empty state.
#name#.clear(row) Resets a row in the stack to empty state.
#name#.clear() Resets all rows in the list to empty state.
#name#.clear_row(row) Resets a single row in the list to empty state.
#name#.delete(row, idx) Removes the element at a specific index in a row and shifts remaining elements.
#name#.delete_item(row, item) Removes the first occurrence of a value from a row in the list.
#name#.get_next_re(row) -> result Returns the next read pointer index with wraparound for a row.
#name#.get_next_wr(row) -> result Returns the next write pointer index with wraparound for a row.
#name#.insert(row, element, idx) Inserts an element at a specific index in a row of the list.
#name#.peek(row) -> result Returns the front element in a row without removing it.
#name#.peek(row) -> result Returns the top element in a row without removing it.
#name#.peek(row, idx) -> result Returns an element at a specific index in a row without removing it.
#name#.peek_end(row) -> result Returns the last element in a row without removing it.
#name#.pop(row) -> result Returns and removes the front element from a row in the queue.
#name#.pop(row) -> result Returns and removes the top element from a row in the stack.
#name#.pop(row) -> result Returns and removes the last element from a row in the list.
#name#.push(row, element) Adds an element to the back of a row in the queue.
#name#.push(row, element) Adds an element to the top of a row in the stack.
#name#.retrieve(row, idx) -> result Returns and removes the element at a specific index in a row.
#name#.retrieve_item(row, item) -> result Finds the first occurrence of a value in a row, removes it, and returns its inde...

Macros

adt.2DListFunctions(#name#)

Generates all operational functions for a 2D list instance.

Preconditions: Must be called after a Create2DList macro for the same instance name.

Parameter Description
#name# list instance name

adt.2DQueueFunctions(#name#)

Generates all operational functions for a 2D queue instance.

Preconditions: Must be called after a Create2DQueue macro for the same instance name.

Parameter Description
#name# queue instance name

adt.2DStackFunctions(#name#)

Generates all operational functions for a 2D stack instance.

Preconditions: Must be called after a Create2DStack macro for the same instance name.

Parameter Description
#name# stack instance name

adt.Create2DList(#name#, #row1#, #row2#)

Constructs a 2D integer list with random access support.

Parameter Description
#name# list instance name
#row1# number of rows
#row2# number of columns per row

adt.Create2DQueue(#name#, #row#, #size#)

Constructs a 2D integer queue with ring buffer storage per row.

Parameter Description
#name# queue instance name
#row# number of rows
#size# maximum capacity per row

adt.Create2DStack(#name#, #row#, #size#)

Constructs a 2D integer stack.

Parameter Description
#name# stack instance name
#row# number of rows
#size# maximum capacity per row

Functions

#name#.append.fast(row, element)

Inserts element at end of row without capacity checking.

Parameter Description
row row index
element element to put in the list

#name#.clear(row)

Resets a row in the queue to empty state.

Parameter Description
row row index

#name#.clear(row)

Resets a row in the stack to empty state.

Parameter Description
row row index

#name#.clear()

Resets all rows in the list to empty state.


#name#.clear_row(row)

Resets a single row in the list to empty state.

Parameter Description
row the row of the list

#name#.delete(row, idx)

Removes the element at a specific index in a row and shifts remaining elements.

Parameter Description
row the row of the list
idx the index of the element to delete

#name#.delete_item(row, item)

Removes the first occurrence of a value from a row in the list.

Parameter Description
row the row of the list
item the value to find and delete

#name#.get_next_re(row) -> result

Returns the next read pointer index with wraparound for a row.

Parameter Description
row row index

Returns: result — next read pointer index


#name#.get_next_wr(row) -> result

Returns the next write pointer index with wraparound for a row.

Parameter Description
row row index

Returns: result — next write pointer index


#name#.insert(row, element, idx)

Inserts an element at a specific index in a row of the list.

Preconditions: Row must not be full.

Parameter Description
row the row of the list
element element to insert
idx the desired index for the element

#name#.peek(row) -> result

Returns the front element in a row without removing it.

Preconditions: 2DQueue row must not be empty.

Parameter Description
row row index

Returns: result — front element in the row, or adt.TASK_FAIL if the row is empty


#name#.peek(row) -> result

Returns the top element in a row without removing it.

Preconditions: 2DStack row must not be empty.

Parameter Description
row row index

Returns: result — top element in the row, or adt.TASK_FAIL if the row is empty


#name#.peek(row, idx) -> result

Returns an element at a specific index in a row without removing it.

Preconditions: The row must not be empty.

Parameter Description
row the row of the list
idx the index of the element to peek

Returns: result — element at the specified index, or adt.TASK_FAIL if the row is empty or index is invalid


#name#.peek_end(row) -> result

Returns the last element in a row without removing it.

Parameter Description
row the row of the list

Returns: result


#name#.pop(row) -> result

Returns and removes the front element from a row in the queue.

Preconditions: 2DQueue row must not be empty.

Parameter Description
row row index

Returns: result — front element in the row, or adt.TASK_FAIL if the row is empty


#name#.pop(row) -> result

Returns and removes the top element from a row in the stack.

Preconditions: 2DStack row must not be empty.

Parameter Description
row row index

Returns: result — top element in the row, or adt.TASK_FAIL if the row is empty


#name#.pop(row) -> result

Returns and removes the last element from a row in the list.

Preconditions: The row must not be empty.

Parameter Description
row the row of the list

Returns: result — last element in the row, or adt.TASK_FAIL if the row is empty


#name#.push(row, element)

Adds an element to the back of a row in the queue.

Preconditions: 2DQueue row must not be full.

Parameter Description
row row index
element element to put in the queue

#name#.push(row, element)

Adds an element to the top of a row in the stack.

Preconditions: 2DStack row must not be full.

Parameter Description
row row index
element element to put in the stack

#name#.retrieve(row, idx) -> result

Returns and removes the element at a specific index in a row.

Preconditions: The row must not be empty.

Parameter Description
row the row of the list
idx the index of the element to retrieve

Returns: result — element at the specified index, or adt.TASK_FAIL if the row is empty or index is invalid


#name#.retrieve_item(row, item) -> result

Finds the first occurrence of a value in a row, removes it, and returns its index.

Preconditions: The row must not be empty.

Parameter Description
row the row of the list
item the value to find and remove

Returns: result — index of the removed item, or -1 if not found


Example

// TODO: Add usage example

See Also