Class List<T>Sealed

Doubly linked list. Refer to the golang standard library implementation

Type Parameters

  • T

Hierarchy

Implements

Constructors

Properties

length_: number = 0

record linked list length

opts_: undefined | Options<T>
root_: ListElement<T>

sentinel list element, only root, root.prev, and root.next are used

Accessors

  • get reverse(): Iterable<T>
  • Sealed

    Returns an object that implements a js Iterable, but it traverses the data in reverse

    Returns Iterable<T>

Methods

  • clear the list

    Remarks

    It will cause a bug if a call to remove is passed after calling clear and an element before clear is passed in. like this

    const l = new List<number>()
    const ele = l.pushBack(1)
    l.cear()
    console.log((l.remove(ele)) // output true
    console.log(l.length) // output -1

    This bug is generated because the element records which linked list it is in and the clear function does not clear the mark .

    So remove(ele) mistakenly deletes the expired element. To solve this problem, it is necessary to traverse the linked list once in 'clear' to clear all tags, but this will damage efficiency. However, this bug is not common and the caller can be avoided, so I'm not going to fix it.

    You can also avoid this bug by passing in an empty implementation of the callback function, because calling the callback for all elements also requires traversing the list once, so in this case the code also empties the token before the callback.

    const l = new List<number>()
    const ele = l.pushBack(1)
    l.cear(()=>{})
    console.log((l.remove(ele)) // output false
    console.log(l.length) // output 0

    Parameters

    • Optional callback: DeleteCallback<T>

      call the callback on the removed element

    Returns void

  • Traverse the container looking for elements until the callback returns true, then stop looking

    Returns

    whether the element was found

    Parameters

    • callback: ValidCallback<T>

      Determine whether it is the element to be found

    • Optional reverse: boolean

      If true, traverse the container in reverse order

    Returns boolean

  • return js iterator

    Parameters

    • Optional reverse: boolean

      If true, returns an iterator to traverse in reverse

    Returns Iterator<T, any, undefined>

  • Adds all the elements of an container into a string, separated by the specified separator string.

    Type Parameters

    • TO

    Parameters

    • Optional separator: string

      A string used to separate one element of the container from the next in the resulting string. If omitted, the array elements are separated with a comma.

    • Optional callback: MapCallback<T, TO>
    • Optional reverse: boolean

      If true, traverse the container in reverse order

    Returns string

Generated using TypeDoc