InsertOrderedSet

An InsertOrderedSet is a data structure with the following properties:

  1. Contains unique values.
  2. O(1) manipulation operations (e.g. insert, delete)
  3. Preserves insertion order when converting to a list.

This data structure loosely conforms to the Set protocol, I'll be adding full support soon.

Installation

If available in Hex, the package can be installed as:

  1. Add insert_ordered_set to your list of dependencies in mix.exs:

    def deps do

     [{:insert_ordered_set, "~> 0.0.1"}]

    end

  2. Ensure insert_ordered_set is started before your application:

    def application do

     [applications: [:insert_ordered_set]]

    end

Usage

Currently supported Set methods:

I've added an additional method wherein you can tell the to_list function to produce the list in :asc (insertion order) or :desc (reverse insertion order) order.

Unique values

[1, 1, 2]
|> InsertOrderedSet.new
|> InsertOrderedSet.to_list  # [ 1, 2 ]

Insertion order preservation

Try the following with MapSet:

["b", "c", "a"]
|> InsertOrderedSet.new
|> InsertOrderedSet.to_list  # ["b", "c", "a"]

Retrieve list in reverse insertion order

["b", "c", "a"]
|> InsertOrderedSet.new
|> InsertOrderedSet.to_list(:desc)  # ["a", "c", "b"]

TODO