Skip to content

Commit

Permalink
Added public modifiers to functions.
Browse files Browse the repository at this point in the history
  • Loading branch information
Olcay Taner YILDIZ committed Aug 27, 2020
1 parent 600ed8f commit 683ffe3
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 22 deletions.
6 changes: 3 additions & 3 deletions Sources/DataStructure/Cache/CacheLinkedList.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public class CacheLinkedList<K, T>{

- Parameter cacheNode : CacheNode type input to remove.
*/
func removeGiven(cacheNode: CacheNode<K, T>){
public func removeGiven(cacheNode: CacheNode<K, T>){
let previous : CacheNode<K, T>? = cacheNode.getPrevious()
let next : CacheNode<K, T>? = cacheNode.getNext()
if previous != nil{
Expand All @@ -43,7 +43,7 @@ public class CacheLinkedList<K, T>{

- Parameter cacheNode : CacheNode type input to add to the doubly list.
*/
func add(cacheNode: CacheNode<K, T>){
public func add(cacheNode: CacheNode<K, T>){
cacheNode.setPrevious(previous: nil)
if self.head != nil{
cacheNode.setNext(next: self.head!)
Expand All @@ -61,7 +61,7 @@ public class CacheLinkedList<K, T>{

- Returns: CacheNode type output tail which is removed from doubly list.
*/
func remove() -> CacheNode<K, T>{
public func remove() -> CacheNode<K, T>{
let removed : CacheNode<K, T> = self.tail!
self.tail = self.tail!.getPrevious()
if self.tail == nil{
Expand Down
12 changes: 6 additions & 6 deletions Sources/DataStructure/Cache/CacheNode.swift
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public class CacheNode<K, T>{

- Returns: data value.
*/
func getData() -> T{
public func getData() -> T{
return self.data
}

Expand All @@ -42,7 +42,7 @@ public class CacheNode<K, T>{

- Returns: key value.
*/
func getKey() -> K{
public func getKey() -> K{
return self.key
}

Expand All @@ -51,7 +51,7 @@ public class CacheNode<K, T>{

- Returns: previous CacheNode.
*/
func getPrevious() -> CacheNode?{
public func getPrevious() -> CacheNode?{
return self.previous
}

Expand All @@ -60,7 +60,7 @@ public class CacheNode<K, T>{

- Returns: next CacheNode.
*/
func getNext() -> CacheNode?{
public func getNext() -> CacheNode?{
return self.next
}

Expand All @@ -69,7 +69,7 @@ public class CacheNode<K, T>{

- Parameter previous : previous CacheNode.
*/
func setPrevious(previous: CacheNode?){
public func setPrevious(previous: CacheNode?){
self.previous = previous
}

Expand All @@ -78,7 +78,7 @@ public class CacheNode<K, T>{

- Parameter: next : next CacheNode.
*/
func setNext(next: CacheNode){
public func setNext(next: CacheNode){
self.next = next
}

Expand Down
8 changes: 4 additions & 4 deletions Sources/DataStructure/Cache/LRUCache.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public class LRUCache<K: Hashable, T>{
A constructor of LRUCache class which takes cacheSize as input. It creates new CacheLinkedList and
HashMap.

- Parameter cacheSize : Integer input funcining cache size.
- Parameter cacheSize : Integer input public funcining cache size.
*/
init(cacheSize: Int){
self.cacheSize = cacheSize
Expand All @@ -33,7 +33,7 @@ public class LRUCache<K: Hashable, T>{

- Returns: true if the HashMap has the given key, false otherwise.
*/
func contains(key: K) -> Bool{
public func contains(key: K) -> Bool{
return self.map[key] != nil
}

Expand All @@ -47,7 +47,7 @@ public class LRUCache<K: Hashable, T>{

- Returns: data value if the dictionary has the given key, None otherwise.
*/
func get(key: K) -> T?{
public func get(key: K) -> T?{
if self.map[key] != nil{
let cacheNode : CacheNode<K, T> = self.map[key]!
self.cache.removeGiven(cacheNode: cacheNode)
Expand All @@ -68,7 +68,7 @@ public class LRUCache<K: Hashable, T>{
- key : object type input.
- data : object type input
*/
func add(key: K, data: T){
public func add(key: K, data: T){
if self.map.count == self.cacheSize{
let removed : CacheNode<K, T> = self.cache.remove()
self.map[removed.getKey()] = nil
Expand Down
18 changes: 9 additions & 9 deletions Sources/DataStructure/CounterHashMap.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public class CounterHashMap<K : Hashable>{

- Parameter key : key to put.
*/
func put(key: K){
public func put(key: K){
if data[key] != nil{
data[key] = data[key]! + 1
} else{
Expand All @@ -39,7 +39,7 @@ public class CounterHashMap<K : Hashable>{
- key : key to put.
- N : to increment value.
*/
func putNTimes(key: K, N: Int){
public func putNTimes(key: K, N: Int){
if data[key] != nil{
data[key]! += N
} else{
Expand All @@ -55,15 +55,15 @@ public class CounterHashMap<K : Hashable>{

- Returns: the value corresponding given key, 0 if it is not mapped.
*/
func count(key: K) -> Int{
public func count(key: K) -> Int{
if data[key] != nil{
return data[key]!
} else {
return 0
}
}

func size() -> Int{
public func size() -> Int{
return data.count
}

Expand All @@ -72,7 +72,7 @@ public class CounterHashMap<K : Hashable>{

- Returns: accumulated counts.
*/
func sumOfCounts() -> Int{
public func sumOfCounts() -> Int{
var total : Int = 0
for key in data.keys{
total += data[key]!
Expand All @@ -91,7 +91,7 @@ public class CounterHashMap<K : Hashable>{

- Returns: object type maxKey if greater than the given threshold, None otherwise.
*/
func max(threshold: Double = 0.0) -> K?{
public func max(threshold: Double = 0.0) -> K?{
var maxCount : Int = 0
var total : Int = 0
var maxKey : K? = nil
Expand All @@ -114,7 +114,7 @@ public class CounterHashMap<K : Hashable>{

- Parameter toBeAdded : CounterHashMap to be added to this counterHashMap.
*/
func add(toBeAdded: CounterHashMap){
public func add(toBeAdded: CounterHashMap){
for value in toBeAdded.data.keys{
self.putNTimes(key: value, N: toBeAdded.data[value]!)
}
Expand All @@ -125,11 +125,11 @@ public class CounterHashMap<K : Hashable>{
mappings contained in this map and adds each entry to the result list. Then sort this list
according to their values and returns a list which is a sublist of result with N elements.

- Parameter N : nteger value for funcining size of the sublist.
- Parameter N : nteger value for public funcining size of the sublist.

- Returns: a sublist of N element.
*/
func topN(N: Int) -> Array<(item:K, count:Int)>{
public func topN(N: Int) -> Array<(item:K, count:Int)>{
var result : Array<(item:K, count:Int)> = []
for key in data.keys{
result.append((key, data[key]!))
Expand Down

0 comments on commit 683ffe3

Please sign in to comment.