Skip to content

Commit

Permalink
Pretty printing toString methods added.
Browse files Browse the repository at this point in the history
  • Loading branch information
Mikael Vejdemo-Johansson committed Dec 4, 2023
1 parent 3b3ca18 commit 3ec6b91
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions src/commonMain/kotlin/org/appliedtopology/tda4j/Sets.kt
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ open class ArrayMutableSortedSetBase<T : Comparable<T>>(capacity: Int = 8) {
}
}

class ArrayMutableSortedSet<T : Comparable<T>>(capacity: Int) : ArrayMutableSortedSetBase<T>(capacity), MutableSet<T> {
class ArrayMutableSortedSet<T : Comparable<T>>(capacity: Int = 8) : ArrayMutableSortedSetBase<T>(capacity), MutableSet<T> {
override fun remove(element: T): Boolean {
val index = _set.binarySearch(element)
if (index < 0) {
Expand All @@ -54,6 +54,10 @@ class ArrayMutableSortedSet<T : Comparable<T>>(capacity: Int) : ArrayMutableSort
return true
}
}

override fun toString(): String {
return "ArrayMutableSortedSet(${_set.joinToString()})"
}
}
typealias MutableSortedSet<V> = ArrayMutableSortedSet<V>

Expand All @@ -75,12 +79,16 @@ open class ArrayMutableSortedMap<K : Comparable<K>, V>(capacity: Int = 8, defaul
value = newValue
return value
}

override fun toString(): String {
return "PairEntry($key, $value)"
}
}

override val entries: MutableSet<MutableMap.MutableEntry<K, V>>
get() = _set.zip(_values).map { (k, v) -> PairEntry(k, v) }.toMutableSet()
override val keys: MutableSet<K>
get() = this as ArrayMutableSortedSet<K>
get() = _set.toMutableSet()

override val values: MutableCollection<V>
get() = _values.toMutableList()
Expand Down Expand Up @@ -116,6 +124,10 @@ open class ArrayMutableSortedMap<K : Comparable<K>, V>(capacity: Int = 8, defaul
return null
}
}

override fun toString(): String {
return "ArrayMutableSortedMap(${entries.joinToString()})"
}
}

open class MutableBitSet(var capacity: Int) : MutableSet<Int> {
Expand Down

0 comments on commit 3ec6b91

Please sign in to comment.