diff --git a/yorkie/src/main/kotlin/dev/yorkie/util/SplayTreeSet.kt b/yorkie/src/main/kotlin/dev/yorkie/util/SplayTreeSet.kt index 8dc67a205..b65c98f8b 100644 --- a/yorkie/src/main/kotlin/dev/yorkie/util/SplayTreeSet.kt +++ b/yorkie/src/main/kotlin/dev/yorkie/util/SplayTreeSet.kt @@ -73,7 +73,7 @@ internal class SplayTreeSet( */ fun indexOf(value: V?): Int { val node = valueToNodes[value] - if (node == null || !node.hasLinks) { + if (node == null || node !== root && !node.hasLinks) { return -1 } var index = 0 diff --git a/yorkie/src/test/kotlin/dev/yorkie/util/SplayTreeSetTest.kt b/yorkie/src/test/kotlin/dev/yorkie/util/SplayTreeSetTest.kt index 8723bcf13..f382f5360 100644 --- a/yorkie/src/test/kotlin/dev/yorkie/util/SplayTreeSetTest.kt +++ b/yorkie/src/test/kotlin/dev/yorkie/util/SplayTreeSetTest.kt @@ -99,6 +99,15 @@ class SplayTreeSetTest { assertIfRangeCutOff(nodes, 3..7) } + @Test + fun `should handle indexOf correctly with single node`() { + val node = Node("A") + target.insert(node) + assertEquals(0, target.indexOf(node)) + target.delete(node) + assertEquals(-1, target.indexOf(node)) + } + private fun assertIfRangeCutOff(nodes: List, targetRange: IntRange) { assertEquals( 0,