InPlace.LinkedList (inplace v0.7.1)

Copy Markdown

Singly linked list The data entries are stored as integers. They will be interpreted (as references) by the calling application. Note: indices are 1-based. Options:

  • mode :: :singly_linked | :doubly_linked

  • circular :: boolean() optional, false by default;
  • deletion :: :reclaim | :hide | :rewind Handles if the element pointer could be restored later (see delete_pointer/2), and how to restore it: :reclaim (default) - element can not be restored, the pointer will be put back to the allocation pool; :hide - element can be restored by re-linking with it's former left and right neighbors; The element stays in the list, but can not be reached except by directly addressed by it's pointer. The element can be put back to it's position by reconnecting previously prior and next elements back to that element (see hide/2 and restore/2); :rewind - if specified, the special stack of removed element pointers is maintained. The effect of removal will be the same as for :hide, except that The elements can be restored in the reverse order of their removal by using rewind/1.

  • :mapper_fun # maps data entries to application data optional, &Function.identity/1 by default

Summary

Functions

add_first(list, data)

append(list, data)

available(list)

circuit(list, pointers)

This will create a circuit out of the list of pointers.

!!!!! Hazard warning !!!!! If you want to avoid infinite loops while iterating over the list that contains circuits, make sure that you start the iteration within the circuit (using :start option fir iterate/2).

For instance

import InPlace.LinkedList
ll = new(Enum.to_list(1..10))
circuit(ll, [2, 4, 6])
iterate, start: 1, action: fn p -> IO.inspect(p) end

will loop indefinitely, as the iteration will be trapped in 2 -> 4 -> 6 circuit once entering it from 1 pointer.

data(list, pointer)

delete(list, position)

Delete element at position (1-based)

delete_pointer(list, pointer)

empty?(list)

get(list, position)

Get element at position (1-based)

head(list)

inc_size(list, delta)

insert(list, position, data)

Insert data element at position (1-based)

iterate(list, action, opts \\ [])

new(values_or_size, opts \\ [])

next(list, pointer)

pointer_deleted?(list, pointer)

prev(list, pointer)

reduce(list, initial_value, reducer \\ nil)

restore_pointer(list, pointer)

rewind(list)

set_data(list, pointer, data)

size(list)

tail(list)

to_list(list)