Fast substring in scala

ov7a

According to Time complexity of Java's substring(), java's substring takes linear time. Is there a faster way (may be in some cases)? I may suggest iterator, but suspect that it also takes O(n).

val s1: String  = s.iterator.drop(5).mkString

But several operations on an iterator would be faster than same operations on string, right?

ymonad

If you need to edit very long string, consider using data structure called Rope.

Scalaz library has Cord class which is implementation of modified version of Rope.

A Cord is a purely functional data structure for efficiently storing and manipulating Strings that are potentially very long. Very similar to Rope[Char], but with better constant factors and a simpler interface since it's specialized for Strings.

この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。

侵害の場合は、連絡してください[email protected]

編集
0

コメントを追加

0

関連記事