-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add specialized Byte/CharTrieOfOneSingleChar.
- Loading branch information
1 parent
7cdd157
commit 3c2f3fe
Showing
9 changed files
with
109 additions
and
12 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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
34 changes: 34 additions & 0 deletions
34
...shofer.fastdoubleparser/ch/randelshofer/fastdoubleparser/bte/ByteTrieOfOneSingleByte.java
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,34 @@ | ||
/* | ||
* @(#)ByteTrieOfOne.java | ||
* Copyright © 2024 Werner Randelshofer, Switzerland. MIT License. | ||
*/ | ||
package ch.randelshofer.fastdoubleparser.bte; | ||
|
||
import java.nio.charset.StandardCharsets; | ||
import java.util.Set; | ||
|
||
class ByteTrieOfOneSingleByte implements ByteTrie { | ||
private final byte ch; | ||
|
||
public ByteTrieOfOneSingleByte(Set<String> set) { | ||
if (set.size() != 1) throw new IllegalArgumentException("set size must be 1, size=" + set.size()); | ||
byte[] chars = set.iterator().next().getBytes(StandardCharsets.UTF_8); | ||
if (chars.length != 1) throw new IllegalArgumentException("char size must be 1, size=" + set.size()); | ||
ch = chars[0]; | ||
} | ||
|
||
public ByteTrieOfOneSingleByte(byte ch) { | ||
this.ch = ch; | ||
} | ||
|
||
|
||
@Override | ||
public int match(byte[] str) { | ||
return match(str, 0, str.length); | ||
} | ||
|
||
@Override | ||
public int match(byte[] str, int startIndex, int endIndex) { | ||
return startIndex < endIndex && str[startIndex] == ch ? 1 : 0; | ||
} | ||
} |
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
37 changes: 37 additions & 0 deletions
37
...shofer.fastdoubleparser/ch/randelshofer/fastdoubleparser/chr/CharTrieOfOneSingleChar.java
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,37 @@ | ||
/* | ||
* @(#)ByteTrieOfOne.java | ||
* Copyright © 2024 Werner Randelshofer, Switzerland. MIT License. | ||
*/ | ||
package ch.randelshofer.fastdoubleparser.chr; | ||
|
||
import java.util.Set; | ||
|
||
class CharTrieOfOneSingleChar implements CharTrie { | ||
private final char ch; | ||
|
||
public CharTrieOfOneSingleChar(Set<String> set) { | ||
if (set.size() != 1) throw new IllegalArgumentException("set size must be 1, size=" + set.size()); | ||
char[] chars = set.iterator().next().toCharArray(); | ||
if (chars.length != 1) throw new IllegalArgumentException("char size must be 1, size=" + set.size()); | ||
ch = chars[0]; | ||
} | ||
|
||
public CharTrieOfOneSingleChar(char ch) { | ||
this.ch = ch; | ||
} | ||
|
||
@Override | ||
public int match(CharSequence str, int startIndex, int endIndex) { | ||
return startIndex < endIndex && str.charAt(startIndex) == ch ? 1 : 0; | ||
} | ||
|
||
@Override | ||
public int match(char[] str) { | ||
return match(str, 0, str.length); | ||
} | ||
|
||
@Override | ||
public int match(char[] str, int startIndex, int endIndex) { | ||
return startIndex < endIndex && str[startIndex] == ch ? 1 : 0; | ||
} | ||
} |
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