- Notifications
You must be signed in to change notification settings - Fork84
Algorithm is a library of tools that is used to create intelligent applications.
License
CosmicMind/Algorithm
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
Algorithm is a library of tools that is used to create intelligent applications.
- Probability Tools
- Expected Value
- Programmable Probability Blocks
- Array Extensions
- Set Extensions
- DoublyLinkedList
- Stack
- Queue
- Deque
- RedBlackTree
- SortedSet
- SortedMultiSet
- SortedDictionary
- SortedMultiDictionary
- iOS 8.0+ / Mac OS X 10.9+
- Xcode 8.0+
- If youneed help, useStack Overflow. (Tag 'cosmicmind')
- If you'd like toask a general question, useStack Overflow.
- If youfound a bug,and can provide steps to reliably reproduce it, open an issue.
- If youhave a feature request, open an issue.
- If youwant to contribute, submit a pull request.
Embedded frameworks require a minimum deployment target of iOS 8.
CocoaPods is a dependency manager for Cocoa projects. You can install it with the following command:
$ gem install cocoapods
To integrate Algorithm's core features into your Xcode project using CocoaPods, specify it in yourPodfile
:
source'https://github.com/CocoaPods/Specs.git'platform:ios,'8.0'use_frameworks!pod'Algorithm','~> 3.1.0'
Then, run the following command:
$ pod install
Carthage is a decentralized dependency manager that builds your dependencies and provides you with binary frameworks.
You can install Carthage with Homebrew using the following command:
$ brew update$ brew install carthage
To integrate Algorithm into your Xcode project using Carthage, specify it in your Cartfile:
github"CosmicMind/Algorithm"
Runcarthage update
to build the framework and drag the builtAlgorithm.framework
into your Xcode project.
Algorithm is a growing project and will encounter changes throughout its development. It is recommended that theChangelog be reviewed prior to updating versions.
The following are samples to see how Algorithm may be used within your applications.
- Visit theSamples repo to see example projects using Algorithm.
Each data structure within Algorithm is equipped with probability tools.
For example, determining the probability of rolling a 3 using a die of 6 numbers.
letdie=[Int](arrayLiteral:1,2,3,4,5,6)if0.1< die.probability(of:3) // Do something ...}
For conditional probabilities that require a more complex calculation, use block statements.
letdie=[Int](arrayLiteral:1,2,3,4,5,6)letpOfX= die.probability{(number)inreturn5< number ||0== number%3}if0.33< pOfX{// Do something ...}
The expected value of rolling a 3 or 6 with 100 trials using a die of 6 numbers.
letdie=[Int](arrayLiteral:1,2,3,4,5,6)if20< die.expectedValue(trials:100, for:3,6){// Do something ...}
The DoublyLinkedList data structure is excellent for large growing collections of data. Below is an example of its usage.
varlistA=DoublyLinkedList<Int>() listA.insert(atFront:3)listA.insert(atFront:2)listA.insert(atFront:1)varlistB=DoublyLinkedList<Int>()listB.insert(atBack:4)listB.insert(atBack:5)listB.insert(atBack:6)varlistC= listA+ listBlistC.cursorToFront()varvalue= listC.cursorwhilenil!= value{ // Do something ... value= listC.next()}
The Stack data structure is a container of objects that are inserted and removed according to the last-in-first-out (LIFO) principle. Below is an example of its usage.
varstack=Stack<Int>()stack.push(1)stack.push(2)stack.push(3)while !stack.isEmpty{letvalue= stack.pop()// Do something ...}
The Queue data structure is a container of objects that are inserted and removed according to the first-in-first-out (FIFO) principle. Below is an example of its usage.
varqueue=Queue<Int>()queue.enqueue(1)queue.enqueue(2)queue.enqueue(3)while !queue.isEmpty{letvalue= queue.dequeue() // Do something ...}
The Deque data structure is a container of objects that are inserted and removed according to the first-in-first-out (FIFO) and last-in-first-out (LIFO) principle. Essentially, a Deque is a Stack and Queue combined. Below are examples of its usage.
vardequeA=Deque<Int>()dequeA.insert(atBack:1)dequeA.insert(atBack:2)dequeA.insert(atBack:3)while !dequeA.isEmpty{letvalue= dequeA.removeAtFront()// Do something ...}vardequeB=Deque<Int>()dequeB.insert(atBack:4)dequeB.insert(atBack:5)dequeB.insert(atBack:6)while !dequeB.isEmpty{letvalue= dequeB.removeAtFront()// Do something ...}
A RedBlackTree is a Balanced Binary Search Tree that maintains insert, remove, update, and search operations in a complexity of O(logn). The following implementation of a RedBlackTree also includes an order-statistic, which allows the data structure to be accessed using subscripts like an array or dictionary. RedBlackTrees may store unique keys or non-unique key values. Below is an example of its usage.
varages=RedBlackTree<String,Int>(uniqueKeys:true)ages.insert(value:16, for:"Sarah")ages.insert(value:12, for:"Peter")ages.insert(value:23, for:"Alex")letnode=ages[1]if"Peter"== node.key{ // Do something ...}
SortedSets are a powerful data structure for algorithm and analysis design. Elements within a SortedSet are unique and insert, remove, and search operations have a complexity of O(logn). The following implementation of a SortedSet also includes an order-statistic, which allows the data structure to be accessed using an index subscript like an array. Below are examples of its usage.
letsetA=SortedSet<Int>(elements:1,2,3)letsetB=SortedSet<Int>(elements:4,3,6)letsetC=SortedSet<Int>(elements:7,1,2)letsetD=SortedSet<Int>(elements:1,7)letsetE=SortedSet<Int>(elements:1,6,7)// Union.setA+ setBsetA.union(setB)// Intersection.setC.intersection(setD)// Subset.setD< setCsetD.isSubset(of: setC)// Superset.setD> setCsetD.isSuperset(of: setC)// Contains.setE.contains(setA.first!)// Probability.setE.probability(of: setA.first!, setA.last!)
A SortedMultiSet is identical to a SortedSet, except that a SortedMultiSet allows non-unique elements. Look atSortedSet for examples of its usage.
A SortedDictionary is a powerful data structure that maintains a sorted set of keys with value pairs. Keys within a SortedDictionary are unique and insert, remove, update, and search operations have a complexity of O(logn).
A SortedMultiDictionary is identical to a SortedDictionary, except that a SortedMultiDictionary allows non-unique keys. Below is an example of its usage.
structStudent{varname:String}letsarah=Student(name:"Sarah")letpeter=Student(name:"Peter")letalex=Student(name:"Alex")varstudents=SortedMultiDictionary<String,Student>()students.insert(value: sarah, for: sarah.name)students.insert(value: peter, for: peter.name)students.insert(value: alex, for: alex.name)forstudentin students{ // Do something ...}
The MIT License (MIT)
Copyright (C) 2019, CosmicMind, Inc.http://cosmicmind.com.All rights reserved.
Permission is hereby granted, free of charge, to any person obtaining a copyof this software and associated documentation files (the "Software"), to dealin the Software without restriction, including without limitation the rightsto use, copy, modify, merge, publish, distribute, sublicense, and/or sellcopies of the Software, and to permit persons to whom the Software isfurnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included inall copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS ORIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THEAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHERLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS INTHE SOFTWARE.
About
Algorithm is a library of tools that is used to create intelligent applications.
Topics
Resources
License
Uh oh!
There was an error while loading.Please reload this page.
Stars
Watchers
Forks
Packages0
Uh oh!
There was an error while loading.Please reload this page.
Contributors3
Uh oh!
There was an error while loading.Please reload this page.