gim v1.2.2 Gim.Index View Source

Internal helper module to handle indexes.

Link to this section Summary

Functions

Adds an id to the given index

Returns the difference of two given indexes

Intersects a list of indexes

Intersects the given indexes

Intersects a list of indexes

Joins the given indexes

Turns a given list into an index

Removes an id from the given index

Link to this section Types

Link to this section Functions

Link to this function

add(index, id)

View Source
add(index :: index(), id :: id()) :: index()

Adds an id to the given index

iex> add([], 42)
[42]

iex> add([404, 23, 13], 42)
[404, 42, 23, 13]

Since ids have to be unique, duplicates are prevented

iex> add([404, 42, 23, 13], 42)
[404, 42, 23, 13]
Link to this function

difference(index_a, index_b)

View Source

Returns the difference of two given indexes

iex> difference([99, 66, 77, 50, 30, 10, 0], [99, 70, 60, 50, 11, 10, 1, 0])
{[77, 66, 30], [70, 60, 11, 1]}

iex> difference([5, 4, 3, 2, 1], [5, 4, 3, 2, 1])
{[], []}

iex> difference([], [])
{[], []}
Link to this function

intersect(lists)

View Source
intersect(indexes :: [index()]) :: index()

Intersects a list of indexes

iex> intersect([[99, 77, 66, 50, 30, 10, 0], [99, 70, 60, 50, 11, 10, 1, 0], [99, 50, 10]])
[99, 50, 10]
Link to this function

intersect(index_a, index_b)

View Source
intersect(index_a :: index(), index_b :: index()) :: index()

Intersects the given indexes

iex> intersect([99, 66, 77, 50, 30, 10, 0], [99, 70, 60, 50, 11, 10, 1, 0])
[99, 50, 10, 0]

iex> intersect([], [99, 70, 60, 50, 11, 10, 1, 0])
[]
Link to this function

join(lists)

View Source
join(indexes :: [index()]) :: index()

Intersects a list of indexes

iex> join([[99, 55, 42, 11], [98, 54, 42, 10], [90, 50, 42]])
[99, 98, 90, 55 , 54, 50, 42, 11, 10]
Link to this function

join(index_a, index_b)

View Source
join(index_a :: index(), index_b :: index()) :: index()

Joins the given indexes

iex> join([99, 50, 13], [90, 50, 10])
[99, 90, 50, 13, 10]

iex> join([], [99, 70, 60, 50, 11, 10, 1, 0])
[99, 70, 60, 50, 11, 10, 1, 0]
Link to this function

new(list)

View Source
new(list :: index()) :: index()

Turns a given list into an index

iex> new([10, 13, 6, 60, 2])
[60, 13, 10, 6, 2]

iex> new([2, 2, 2, 3])
[3, 2]
Link to this function

remove(index, id)

View Source
remove(index :: index(), id :: id()) :: index()

Removes an id from the given index

iex> remove([], 42)
[]

iex> remove([404, 42, 23, 13], 42)
[404, 23, 13]