This gist has been superseded by https://github.com/Integralist/Data-Structures and also https://www.integralist.co.uk/data-types-and-data-structures/
Note:
sequential == collection keeps order of population
ordered == collection is re-ordered (implements a Sequence interface)
Tuple
- ordered
- duplicates allowed
Set
- sequential
- no duplicates
Note: Clojure's Set data structure appears to be ordered
#{3 1 2}
,(first #{3 1 2})
returns 1
Linked list
- list contains nodes
- each node holds:
- data
- pointer to the next node
- the last node's pointer points to
null
- this is a singly linked list
- a doubly linked list will also have a pointer to the previous node
- no direct access to individual elements
- you must access the head and navigate until element is found
Array/Vector
- index access
- duplicates allowed
- Vectors are synchronised (i.e. thread-safe)
- Arrays allow operations across multiple threads (i.e. not thread-safe)
- Array size is determined up front
- you cannot remove an element from an Array
- but you can put a null pointer or no value to it
- you cannot remove an element from an Array
- Vector is dynamic (i.e. it can resize dynamically based on new elements added)
- Arrays can't add elements to a specific index, only to the end.
- Vectors are like super Arrays.
List/Sequence
- ordered
- duplicates allowed (but finite size)
Stack
- ordered
- LIFO (last in, first out)
- only actions available are
push
andpop
(push
directs "in",pop
directs "out")
Queue
- ordered
- FIFO (first in, first out)
- only actions available are
enqueue
anddequeue
(enqueue
directs "in",dequeue
directs "out")
I have some questions about Arrays and Vectors as described here, and I wondered why you did not mention Hash/Map/Dictionary data structures?
So, first of all, it feels as though your definition of Arrays and Vectors is very C/C++/Java Centric - is that fair? I mean in that paradigm it's absolutely accurate, as far as I can tell, but here's the thing...
In Clojure there is no such thing as an Array, and like all data structures, Vectors are immutable.
In PHP (not a good start I admit), there is no such thing as a Vector and Arrays are mutable (This is because Arrays in PHP are not actually Arrays, but specialised Hashes, but still...)
On to Hash(Table)/Map/Dictionaries...
Ruby
my_hash = {:name => "Oli"}
puts my_hash[:name]
Oli
my_hash[:surname] = "Godby"
puts my_hash.inspect
{:name => "Oli", :surname => "Godby"}
puts my_hash.keys
name
surname
*In Clojure, Maps are immutable like all other data structures and values.