Skip to content

Commit

Permalink
minor
Browse files Browse the repository at this point in the history
  • Loading branch information
s4ke committed Aug 17, 2016
1 parent 3e62e59 commit b8505a0
Showing 1 changed file with 20 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
*
* @author Martin Braun
*/
public class EfficientString {
public class EfficientString implements Comparable<EfficientString> {

private CharSeq underlying;
private int start;
Expand Down Expand Up @@ -147,4 +147,23 @@ public String toString() {
return this.underlying.subSequence( this.start, this.end );
}

@Override
public int compareTo(EfficientString o) {
//similar to Java's String comparison fn

int len1 = this.codePointLength();
int len2 = o.codePointLength();
int lim = Math.min( len1, len2 );

int k = 0;
while ( k < lim ) {
int c1 = this.codePoint( k );
int c2 = o.codePoint( k );
if ( c1 != c2 ) {
return c1 - c2;
}
k++;
}
return len1 - len2;
}
}

0 comments on commit b8505a0

Please sign in to comment.