diff --git a/core/src/main/kotlin/tw/xcc/gumtree/api/tree/PriorityTreeList.kt b/core/src/main/kotlin/tw/xcc/gumtree/api/tree/PriorityTreeList.kt index 8bab81d..753434e 100644 --- a/core/src/main/kotlin/tw/xcc/gumtree/api/tree/PriorityTreeList.kt +++ b/core/src/main/kotlin/tw/xcc/gumtree/api/tree/PriorityTreeList.kt @@ -1,8 +1,6 @@ package tw.xcc.gumtree.api.tree -import tw.xcc.gumtree.model.BasicTree - -internal interface PriorityTreeList> { +internal interface PriorityTreeList { /** * Inserts the node n in the list. * */ @@ -14,15 +12,15 @@ internal interface PriorityTreeList> { fun open(tree: T) /** - * Returns and removes the set of all nodes which has a priority equals to [peekMax] + * Returns and removes the set of all nodes that has a priority equals to [peekMax] * */ - fun pop(): List + fun pop(): List /** * Returns and removes the set of all nodes which has a priority equals to [peekMax], * and inserts all the children of these nodes in the list. * */ - fun popOpen(): List + fun popOpen(): List /** * Returns the highest priority value of the list. diff --git a/core/src/main/kotlin/tw/xcc/gumtree/api/tree/TreeMappingStorage.kt b/core/src/main/kotlin/tw/xcc/gumtree/api/tree/TreeMappingStorage.kt new file mode 100644 index 0000000..196ceaf --- /dev/null +++ b/core/src/main/kotlin/tw/xcc/gumtree/api/tree/TreeMappingStorage.kt @@ -0,0 +1,27 @@ +package tw.xcc.gumtree.api.tree + +internal interface TreeMappingStorage { + fun addMappingOf(mapping: Pair) + + fun addMappingRecursivelyOf(mapping: Pair) + + fun removeMappingOf(mapping: Pair) + + fun getMappingOfLeft(left: T): Tree? + + fun getMappingOfRight(right: T): Tree? + + fun isLeftMapped(left: T): Boolean + + fun isAnyOfLeftsUnMapped(lefts: Iterable): Boolean + + fun isRightMapped(right: T): Boolean + + fun isAnyOfRightsUnMapped(rights: Iterable): Boolean + + fun areBothUnMapped(mapping: Pair): Boolean + + fun hasUnMappedDescendentOfLeft(left: T): Boolean + + fun hasUnMappedDescendentOfRight(right: T): Boolean +} \ No newline at end of file diff --git a/core/src/main/kotlin/tw/xcc/gumtree/model/MappingStorage.kt b/core/src/main/kotlin/tw/xcc/gumtree/model/MappingStorage.kt index 15f79c8..6022ba7 100644 --- a/core/src/main/kotlin/tw/xcc/gumtree/model/MappingStorage.kt +++ b/core/src/main/kotlin/tw/xcc/gumtree/model/MappingStorage.kt @@ -4,11 +4,12 @@ import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.runBlocking import kotlinx.coroutines.sync.Mutex import kotlinx.coroutines.sync.withLock +import tw.xcc.gumtree.api.tree.TreeMappingStorage /** * The storage for saving the references of the mapping between two GumTrees. (Left and Right) * */ -class MappingStorage { +class MappingStorage : TreeMappingStorage { private val mappingLR = mutableMapOf() private val mappingRL = mutableMapOf() @@ -97,62 +98,62 @@ class MappingStorage { !mappingLR.containsKey(mapping.first) && !mappingRL.containsKey(mapping.second) } - fun addMappingOf(mapping: Pair) = + override fun addMappingOf(mapping: Pair) = runBlocking(Dispatchers.Default) { addMappingImpl(mapping) } - fun addMappingRecursivelyOf(mapping: Pair) = + override fun addMappingRecursivelyOf(mapping: Pair) = runBlocking(Dispatchers.Default) { addMappingRecursivelyImpl(mapping) } - fun removeMappingOf(mapping: Pair) = + override fun removeMappingOf(mapping: Pair) = runBlocking(Dispatchers.Default) { removeMappingImpl(mapping) } - fun getMappingOfLeft(left: GumTree): GumTree? = + override fun getMappingOfLeft(left: GumTree): GumTree? = runBlocking(Dispatchers.Default) { extractMappedTreeOf(left, mappingLR) } - fun getMappingOfRight(right: GumTree): GumTree? = + override fun getMappingOfRight(right: GumTree): GumTree? = runBlocking(Dispatchers.Default) { extractMappedTreeOf(right, mappingRL) } - fun isLeftMapped(left: GumTree): Boolean = + override fun isLeftMapped(left: GumTree): Boolean = runBlocking(Dispatchers.Default) { isMappingExistsIn(mappingLR, left) } - fun isAnyOfLeftsUnMapped(lefts: Iterable): Boolean = + override fun isAnyOfLeftsUnMapped(lefts: Iterable): Boolean = runBlocking(Dispatchers.Default) { isAnyTreeNotExistsIn(mappingLR, lefts) } - fun isRightMapped(right: GumTree): Boolean = + override fun isRightMapped(right: GumTree): Boolean = runBlocking(Dispatchers.Default) { isMappingExistsIn(mappingRL, right) } - fun isAnyOfRightsUnMapped(rights: Iterable): Boolean = + override fun isAnyOfRightsUnMapped(rights: Iterable): Boolean = runBlocking(Dispatchers.Default) { isAnyTreeNotExistsIn(mappingRL, rights) } - fun areBothUnMapped(mapping: Pair): Boolean = + override fun areBothUnMapped(mapping: Pair): Boolean = runBlocking(Dispatchers.Default) { areBothUnMappedImpl(mapping) } - fun hasUnMappedDescendentOfLeft(left: GumTree): Boolean = + override fun hasUnMappedDescendentOfLeft(left: GumTree): Boolean = runBlocking(Dispatchers.Default) { hasUnMappedDescendent(left, mappingLR) } - fun hasUnMappedDescendentOfRight(right: GumTree): Boolean = + override fun hasUnMappedDescendentOfRight(right: GumTree): Boolean = runBlocking(Dispatchers.Default) { hasUnMappedDescendent(right, mappingRL) }