-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Broke out soft operator and shared code: we need a Trie to continue * Added Trie to complete SoftOperator implementation * Fixed issues * Removed Radix * Removed old instructions in comment * Improved completeness of Trie testing, added sonatype release resolver
- Loading branch information
Showing
11 changed files
with
170 additions
and
226 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
51 changes: 51 additions & 0 deletions
51
parsley/shared/src/main/scala/parsley/internal/collection/immutable/Trie.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
/* SPDX-FileCopyrightText: © 2023 Parsley Contributors <https://github.com/j-mie6/Parsley/graphs/contributors> | ||
* SPDX-License-Identifier: BSD-3-Clause | ||
*/ | ||
package parsley.internal.collection.immutable | ||
|
||
import scala.annotation.tailrec | ||
import scala.collection.immutable.IntMap | ||
|
||
private [parsley] class Trie(private val present: Boolean, children: IntMap[Trie]) { | ||
def contains(key: String): Boolean = suffixes(key).present/*contains(key, 0, key.length) | ||
@tailrec private def contains(key: String, idx: Int, sz: Int): Boolean = { | ||
if (idx == sz) present | ||
else childAt(key, idx) match { | ||
case None => false | ||
case Some(t) => t.contains(key, idx + 1, sz) | ||
} | ||
}*/ | ||
|
||
def isEmpty: Boolean = this eq Trie.empty | ||
def nonEmpty: Boolean = !isEmpty | ||
|
||
def suffixes(key: Char): Trie = children.getOrElse(key.toInt, Trie.empty) | ||
def suffixes(key: String): Trie = suffixes(key, 0, key.length) | ||
@tailrec private def suffixes(key: String, idx: Int, sz: Int): Trie = { | ||
if (idx == sz) this | ||
else childAt(key, idx) match { | ||
case None => Trie.empty | ||
case Some(t) => t.suffixes(key, idx + 1, sz) | ||
} | ||
} | ||
|
||
def incl(key: String): Trie = incl(key, 0, key.length) | ||
private def incl(key: String, idx: Int, sz: Int): Trie = { | ||
if (idx == sz && present) this | ||
else if (idx == sz) new Trie(present = true, children) | ||
else childAt(key, idx) match { | ||
case None => new Trie(present, children.updated(key.charAt(idx).toInt, Trie.empty.incl(key, idx + 1, sz))) | ||
case Some(t) => | ||
val newT = t.incl(key, idx + 1, sz) | ||
if (t eq newT) this | ||
else new Trie(present, children.updated(key.charAt(idx).toInt, newT)) | ||
} | ||
} | ||
|
||
private def childAt(key: String, idx: Int) = children.get(key.charAt(idx).toInt) | ||
} | ||
private [parsley] object Trie { | ||
val empty = new Trie(present = false, IntMap.empty) | ||
|
||
def apply(strs: Iterable[String]): Trie = strs.foldLeft(empty)(_.incl(_)) | ||
} |
122 changes: 0 additions & 122 deletions
122
parsley/shared/src/main/scala/parsley/internal/collection/mutable/Radix.scala
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.