- Notifications
You must be signed in to change notification settings - Fork0
Immutable Data Structures for python, for better OOP Programming and Safer Multi-threading.
License
NotificationsYou must be signed in to change notification settings
rinslow/candyland
Folders and files
| Name | Name | Last commit message | Last commit date | |
|---|---|---|---|---|
Repository files navigation
Immutable Data Structures for python.
This is an incomplete list of arguments in favor of immutability:
- immutable objects are simpler to construct, test, and use
- truly immutable objects are always thread-safe
- they help to avoid temporal coupling
- their usage is side-effect free (no defensive copies)
- identity mutability problem is avoided
- they always have failure atomicity
- they are much easier to cache
- they prevent NULL references, which are bad
(Taken fromYegor Bugayenko's blog.)
QueueStackListKeyValuePair(Who needs a key-value pair in python?)
Set- PriorityQueue
- LinkedList
- SortedList
AVLTree- BinarySearchTree
- RedBlackTree
Heap- HashTable
DictionaryBinaryTree
- For suggestion you canmail us
- Suggestions taken fromWikipedia's Data Structures
fromimmutable.abstractimportStacks=Stack(1,2,3)# Can also: s = Stack() or s = Stack([1, 2, 3])prints.push(7).head()# Prints 7prints.pop().head()# Prints 2prints.count()# Prints 3
fromimmutable.abstractimportQueueq=Queue(1,2,3)printq.enqueue(7).head()# Prints 1printq.pop().head()# Prints 1printq.count()# Prints 3
fromimmutable.abstactimportListl=List(1,2,3)print2inlprintl.reverse().append(3).remove(2).extend([1,2]).pop(1).sort().insert(1,3).count(3)
fromimmutable.abstractimportDictionaryd=Dictionary({1:2,4:5})d+Dictionary([(1,2), (3,4)]).append(4,5).pop(1)+Dictionary.from_keys([1,2],0)
fromimmutable.abstractimportSetprint1in (Set(1,2,3)&Set(3,4,5)| [1,2,0]- [3,4]).add(9).update(List(3,3)).pop().remove(2)
fromimmutable.treesimportBinaryTreetree=BinaryTree(BinaryTree(BinaryTree(None,None,2),BinaryTree(BinaryTree(None,None,5),None,6),4),BinaryTree(BinaryTree(None,None,10),BinaryTree(BinaryTree(None,None,15),BinaryTree(None,None,18),16),13),8)printtree,repr(tree),13intree,3.14intree,list(tree),iter(tree),tree.add(1).add(2).remove(3).remove(4)forxinBinaryTree.make([1,2,3,-1,4,7,9,14,8,-23]):printx
fromimmutable.treesimportHeaph1=Heap.make([1,2,3,4,5,6,10,14,11,0,-2],min)h2=Heap([1,2,3],max)h3=Heap([1,2,3])# second parameter is an optional comparator, default is max.printh1.add(1).pop(3).pop(4).add(20).head()
fromimmutable.treesimportAVLTreetree=AVLTree(1,None,None)print2intree.add(1).add(2).pop(4)forxinAVLTree.make([1,2,3,-1,4,7,9,14,8,-23]):printx
About
Immutable Data Structures for python, for better OOP Programming and Safer Multi-threading.
Topics
Resources
License
Uh oh!
There was an error while loading.Please reload this page.
Stars
Watchers
Forks
Releases
No releases published
Packages0
No packages published

