equal
deleted
inserted
replaced
321 final class Lexicon private(rep: Lexicon.Tree) |
321 final class Lexicon private(rep: Lexicon.Tree) |
322 { |
322 { |
323 /* auxiliary operations */ |
323 /* auxiliary operations */ |
324 |
324 |
325 private def dest(tree: Lexicon.Tree, result: List[String]): List[String] = |
325 private def dest(tree: Lexicon.Tree, result: List[String]): List[String] = |
326 (result /: tree.branches.toList) ((res, entry) => |
326 tree.branches.toList.foldLeft(result) { |
327 entry match { case (_, (s, tr)) => |
327 case (res, (_, (s, tr))) => if (s.isEmpty) dest(tr, res) else dest(tr, s :: res) |
328 if (s.isEmpty) dest(tr, res) else dest(tr, s :: res) }) |
328 } |
329 |
329 |
330 private def lookup(str: CharSequence): Option[(Boolean, Lexicon.Tree)] = |
330 private def lookup(str: CharSequence): Option[(Boolean, Lexicon.Tree)] = |
331 { |
331 { |
332 val len = str.length |
332 val len = str.length |
333 @tailrec def look(tree: Lexicon.Tree, tip: Boolean, i: Int): Option[(Boolean, Lexicon.Tree)] = |
333 @tailrec def look(tree: Lexicon.Tree, tip: Boolean, i: Int): Option[(Boolean, Lexicon.Tree)] = |
388 } |
388 } |
389 else tree |
389 else tree |
390 new Lexicon(extend(rep, 0)) |
390 new Lexicon(extend(rep, 0)) |
391 } |
391 } |
392 |
392 |
393 def ++ (elems: IterableOnce[String]): Lexicon = (this /: elems)(_ + _) |
393 def ++ (elems: IterableOnce[String]): Lexicon = elems.foldLeft(this)(_ + _) |
394 |
394 |
395 def ++ (other: Lexicon): Lexicon = |
395 def ++ (other: Lexicon): Lexicon = |
396 if (this eq other) this |
396 if (this eq other) this |
397 else if (is_empty) other |
397 else if (is_empty) other |
398 else this ++ other.raw_iterator |
398 else this ++ other.raw_iterator |