Skip to main content

LinkedList

A doubly-linked list.

Easily inserts and deletes arbitrarily without reordering. A reference to the entry to insert or delete at is required. References to the front and back of the list always exist. When inserting new entries, entry references are provided for convenient removal.

Types

Entry<T>

interface Entry<T> {
remove() → ()
}

An entry in a LinkedList.

Allows removing this entry from the list. This is a constant time operation.

Functions

new

LinkedList.new() → ()

Creates a new LinkedList.

Push

LinkedList:Push(valueT) → Entry<T>

Pushes a new entry to the back of this list.

Unshift

LinkedList:Unshift(valueT) → Entry<T>

Unshifts a new entry to the front of this list.

Shift

LinkedList:Shift() → unknown

Shifts an entry off of the front of this list.

Pop

LinkedList:Pop() → unknown

Pops an entry off of the back of this list.

Peek

LinkedList:Peek() → unknown

Returns the value of the first element in the list without removing it.

PeekBack

LinkedList:PeekBack() → unknown

Returns the value of the last element in the list without removing it.

PeekEntry

LinkedList:PeekEntry() → Entry<unknown>?

Returns the first entry in the list without removing it.

PeekBackEntry

LinkedList:PeekBackEntry() → Entry<unknown>?

Returns the last entry in the list without removing it.

iterating over LinkedList

for  T, Entry<T>  in  LinkedList  do

Iterates over all entries in this list.

Iteration returns the value stored in each entry, followed by an Entry object which can be used to manipulate this entry in the list.

for value, entry in list do
	if value == "foo" then
		entry.remove()
	end
end

IterReversed

LinkedList:IterReversed() → (
T,--

The value stored in the entry

Entry<T>--

The entry object

)

Iterates over all entries in this list in reverse order.

Iteration returns the value stored in each entry, followed by an Entry object which can be used to manipulate this entry in the list.

for value, entry in list:IterReversed() do
	if value == "foo" then
		entry.remove()
	end
end
Show raw api
{
    "functions": [
        {
            "name": "new",
            "desc": "Creates a new LinkedList.",
            "params": [],
            "returns": [],
            "function_type": "static",
            "source": {
                "line": 45,
                "path": "lib/init.lua"
            }
        },
        {
            "name": "Push",
            "desc": "Pushes a new entry to the back of this list.",
            "params": [
                {
                    "name": "value",
                    "desc": "",
                    "lua_type": "T"
                }
            ],
            "returns": [
                {
                    "desc": "",
                    "lua_type": "Entry<T>\n"
                }
            ],
            "function_type": "method",
            "source": {
                "line": 85,
                "path": "lib/init.lua"
            }
        },
        {
            "name": "Unshift",
            "desc": "Unshifts a new entry to the front of this list.",
            "params": [
                {
                    "name": "value",
                    "desc": "",
                    "lua_type": "T"
                }
            ],
            "returns": [
                {
                    "desc": "",
                    "lua_type": "Entry<T>\n"
                }
            ],
            "function_type": "method",
            "source": {
                "line": 103,
                "path": "lib/init.lua"
            }
        },
        {
            "name": "Shift",
            "desc": "Shifts an entry off of the front of this list.",
            "params": [],
            "returns": [
                {
                    "desc": "",
                    "lua_type": "unknown\n"
                }
            ],
            "function_type": "method",
            "source": {
                "line": 121,
                "path": "lib/init.lua"
            }
        },
        {
            "name": "Pop",
            "desc": "Pops an entry off of the back of this list.",
            "params": [],
            "returns": [
                {
                    "desc": "",
                    "lua_type": "unknown\n"
                }
            ],
            "function_type": "method",
            "source": {
                "line": 133,
                "path": "lib/init.lua"
            }
        },
        {
            "name": "Peek",
            "desc": "Returns the value of the first element in the list without removing it.",
            "params": [],
            "returns": [
                {
                    "desc": "",
                    "lua_type": "unknown\n"
                }
            ],
            "function_type": "method",
            "source": {
                "line": 145,
                "path": "lib/init.lua"
            }
        },
        {
            "name": "PeekBack",
            "desc": "Returns the value of the last element in the list without removing it.",
            "params": [],
            "returns": [
                {
                    "desc": "",
                    "lua_type": "unknown\n"
                }
            ],
            "function_type": "method",
            "source": {
                "line": 155,
                "path": "lib/init.lua"
            }
        },
        {
            "name": "PeekEntry",
            "desc": "Returns the first entry in the list without removing it.",
            "params": [],
            "returns": [
                {
                    "desc": "",
                    "lua_type": "Entry<unknown>?\n"
                }
            ],
            "function_type": "method",
            "source": {
                "line": 165,
                "path": "lib/init.lua"
            }
        },
        {
            "name": "PeekBackEntry",
            "desc": "Returns the last entry in the list without removing it.",
            "params": [],
            "returns": [
                {
                    "desc": "",
                    "lua_type": "Entry<unknown>?\n"
                }
            ],
            "function_type": "method",
            "source": {
                "line": 175,
                "path": "lib/init.lua"
            }
        },
        {
            "name": "__iter",
            "desc": "Iterates over all entries in this list.\n\nIteration returns the value stored in each entry, followed by an [Entry<T>]\nobject which can be used to manipulate this entry in the list.\n\n```lua\nfor value, entry in list do\n\tif value == \"foo\" then\n\t\tentry.remove()\n\tend\nend\n```",
            "params": [],
            "returns": [
                {
                    "desc": "",
                    "lua_type": "T"
                },
                {
                    "desc": "",
                    "lua_type": "Entry<T>"
                }
            ],
            "function_type": "method",
            "source": {
                "line": 199,
                "path": "lib/init.lua"
            }
        },
        {
            "name": "IterReversed",
            "desc": "Iterates over all entries in this list in reverse order.\n\nIteration returns the value stored in each entry, followed by an [Entry<T>]\nobject which can be used to manipulate this entry in the list.\n\n```lua\nfor value, entry in list:IterReversed() do\n\tif value == \"foo\" then\n\t\tentry.remove()\n\tend\nend\n```",
            "params": [],
            "returns": [
                {
                    "desc": "The value stored in the entry",
                    "lua_type": "T"
                },
                {
                    "desc": "The entry object",
                    "lua_type": "Entry<T>"
                }
            ],
            "function_type": "method",
            "source": {
                "line": 230,
                "path": "lib/init.lua"
            }
        }
    ],
    "properties": [],
    "types": [
        {
            "name": "Entry<T>",
            "desc": "An entry in a LinkedList.\n\nAllows removing this entry from the list. This is a constant time operation.",
            "fields": [
                {
                    "name": "remove",
                    "lua_type": "() -> ()",
                    "desc": ""
                }
            ],
            "source": {
                "line": 11,
                "path": "lib/init.lua"
            }
        }
    ],
    "name": "LinkedList",
    "desc": "A doubly-linked list.\n\nEasily inserts and deletes arbitrarily without reordering. A reference to the\nentry to insert or delete at is required. References to the front and back of\nthe list always exist. When inserting new entries, entry references are\nprovided for convenient removal.",
    "source": {
        "line": 39,
        "path": "lib/init.lua"
    }
}