mirror of
https://github.com/element-hq/element-android
synced 2024-11-27 11:59:12 +03:00
using value notion instead of key for the elements in the circular cache
This commit is contained in:
parent
4a0cda3268
commit
0385f387d9
3 changed files with 7 additions and 7 deletions
|
@ -259,8 +259,8 @@ private fun createIntCache(cacheSize: Int): Pair<CircularCache<Int>, Array<Int?>
|
||||||
return CircularCache(cacheSize, factory) to internalData!!
|
return CircularCache(cacheSize, factory) to internalData!!
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun CircularCache<Int>.putInOrder(vararg keys: Int) {
|
private fun CircularCache<Int>.putInOrder(vararg values: Int) {
|
||||||
keys.forEach { put(it) }
|
values.forEach { put(it) }
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
|
@ -29,13 +29,13 @@ class CircularCache<T : Any>(cacheSize: Int, factory: (Int) -> Array<T?>) {
|
||||||
private val cache = factory(cacheSize)
|
private val cache = factory(cacheSize)
|
||||||
private var writeIndex = 0
|
private var writeIndex = 0
|
||||||
|
|
||||||
fun contains(key: T): Boolean = cache.contains(key)
|
fun contains(value: T): Boolean = cache.contains(value)
|
||||||
|
|
||||||
fun put(key: T) {
|
fun put(value: T) {
|
||||||
if (writeIndex == cache.size) {
|
if (writeIndex == cache.size) {
|
||||||
writeIndex = 0
|
writeIndex = 0
|
||||||
}
|
}
|
||||||
cache[writeIndex] = key
|
cache[writeIndex] = value
|
||||||
writeIndex++
|
writeIndex++
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -66,7 +66,7 @@ class CircularCacheTest {
|
||||||
return CircularCache(cacheSize, factory) to internalData!!
|
return CircularCache(cacheSize, factory) to internalData!!
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun CircularCache<Int>.putInOrder(vararg keys: Int) {
|
private fun CircularCache<Int>.putInOrder(vararg values: Int) {
|
||||||
keys.forEach { put(it) }
|
values.forEach { put(it) }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue