File tree Expand file tree Collapse file tree 7 files changed +19
-38
lines changed
src/commonMain/kotlin/org/modelix/model/sync/bulk
commonMain/kotlin/org/modelix/kotlin/utils
jsMain/kotlin/org/modelix/kotlin/utils
jvmMain/kotlin/org/modelix/kotlin/utils
model-datastructure/src/commonMain/kotlin/org/modelix/model/persistent Expand file tree Collapse file tree 7 files changed +19
-38
lines changed Original file line number Diff line number Diff line change @@ -21,12 +21,6 @@ kotlin {
21
21
}
22
22
}
23
23
24
- val jvmMain by getting {
25
- dependencies {
26
- implementation(libs.trove4j)
27
- }
28
- }
29
-
30
24
val commonTest by getting {
31
25
dependencies {
32
26
implementation(project(" :model-api" ))
Original file line number Diff line number Diff line change 17
17
package org.modelix.model.sync.bulk
18
18
19
19
import mu.KotlinLogging
20
+ import org.modelix.kotlin.utils.createMemoryEfficientMap
20
21
import org.modelix.model.api.ConceptReference
21
22
import org.modelix.model.api.INode
22
23
import org.modelix.model.api.INodeReference
@@ -256,8 +257,8 @@ class ModelImporter(
256
257
}
257
258
}
258
259
259
- private fun buildExistingIndex (): MemoryEfficientMap <String , INodeReference > {
260
- val localOriginalIdToExisting = MemoryEfficientMap <String , INodeReference >()
260
+ private fun buildExistingIndex (): MutableMap <String , INodeReference > {
261
+ val localOriginalIdToExisting = createMemoryEfficientMap <String , INodeReference >()
261
262
root.getDescendants(true ).forEach { node ->
262
263
node.originalId()?.let { localOriginalIdToExisting[it] = node.reference }
263
264
}
Original file line number Diff line number Diff line change @@ -30,6 +30,7 @@ kotlin {
30
30
}
31
31
val jvmMain by getting {
32
32
dependencies {
33
+ implementation(libs.trove4j)
33
34
}
34
35
}
35
36
val jvmTest by getting {
Original file line number Diff line number Diff line change 14
14
* limitations under the License.
15
15
*/
16
16
17
- package org.modelix.model.sync.bulk
17
+ package org.modelix.kotlin.utils
18
18
19
19
/* *
20
- * Built-in maps like [HashMap] are not the most memory efficient way of map.
21
- * A common issue is that entry objects for every item in the table are created.
22
- * [MemoryEfficientMap] is an internal implementation that we can use
23
- * when the memory overhead becomes too big.
20
+ * Creates a mutable map with less memory overhead.
21
+ * This is an internal API.
24
22
*
23
+ * Built-in maps like [HashMap] are not the not very memory efficient.
24
+ * A common issue is that entry objects for every item in the table are created.
25
25
* Java implementation is optimized to not create entry objects by using a map implementation from another library.
26
26
* The JS implementation is not optimized yet because we did not invest time in finding a suitable library.
27
27
*
28
- * [MemoryEfficientMap] is an internal abstraction .
29
- * The API is therefore kept minimal
28
+ * We did not look into performance implications for storing and retrieving data .
29
+ * Therefore, the memory efficient maps are used sparingly for only the very big maps.
30
30
*/
31
- expect class MemoryEfficientMap <KeyT , ValueT >() {
32
- operator fun set (key : KeyT , value : ValueT )
33
- operator fun get (key : KeyT ): ValueT ?
34
- }
31
+ expect fun <K , V > createMemoryEfficientMap (): MutableMap <K , V >
Original file line number Diff line number Diff line change 14
14
* limitations under the License.
15
15
*/
16
16
17
- package org.modelix.model.sync.bulk
17
+ package org.modelix.kotlin.utils
18
18
19
- import gnu.trove.map.TMap
20
- import gnu.trove.map.hash.THashMap
21
-
22
- actual class MemoryEfficientMap <KeyT , ValueT > {
23
- private val map: TMap <KeyT , ValueT > = THashMap ()
24
-
25
- actual operator fun set (key : KeyT , value : ValueT ) = map.set(key, value)
26
-
27
- actual operator fun get (key : KeyT ) = map[key]
28
- }
19
+ actual fun <K , V > createMemoryEfficientMap (): MutableMap <K , V > = HashMap ()
Original file line number Diff line number Diff line change 14
14
* limitations under the License.
15
15
*/
16
16
17
- package org.modelix.model.sync.bulk
17
+ package org.modelix.kotlin.utils
18
18
19
- actual class MemoryEfficientMap <KeyT , ValueT > {
20
- private val map: MutableMap <KeyT , ValueT > = mutableMapOf ()
19
+ import gnu.trove.map.hash.THashMap
21
20
22
- actual operator fun set (key : KeyT , value : ValueT ) = map.set(key, value)
23
-
24
- actual operator fun get (key : KeyT ) = map[key]
25
- }
21
+ actual fun <K , V > createMemoryEfficientMap (): MutableMap <K , V > = THashMap ()
Original file line number Diff line number Diff line change 15
15
16
16
package org.modelix.model.persistent
17
17
18
+ import org.modelix.kotlin.utils.createMemoryEfficientMap
18
19
import org.modelix.model.IKeyListener
19
20
import org.modelix.model.IKeyValueStore
20
21
import org.modelix.model.lazy.IBulkQuery
@@ -25,7 +26,7 @@ import org.modelix.model.lazy.NonBulkQuery
25
26
open class MapBaseStore : MapBasedStore ()
26
27
27
28
open class MapBasedStore : IKeyValueStore {
28
- private val map: MutableMap <String ?, String ?> = HashMap ()
29
+ private val map: MutableMap <String ?, String ?> = createMemoryEfficientMap ()
29
30
override fun get (key : String ): String? {
30
31
return map[key]
31
32
}
You can’t perform that action at this time.
0 commit comments