io.airlift.slice.Slice.indexOf()方法的使用及代码示例

x33g5p2x  于2022-01-29 转载在 其他  
字(8.9k)|赞(0)|评价(0)|浏览(139)

本文整理了Java中io.airlift.slice.Slice.indexOf()方法的一些代码示例,展示了Slice.indexOf()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Slice.indexOf()方法的具体详情如下:
包路径:io.airlift.slice.Slice
类名称:Slice
方法名:indexOf

Slice.indexOf介绍

[英]Returns the index of the first occurrence of the pattern with this slice. If the pattern is not found -1 is returned. If patten is empty, zero is returned.
[中]返回此切片模式第一次出现的索引。如果找不到模式,则返回-1。如果patten为空,则返回零。

代码示例

代码示例来源:origin: prestodb/presto

  1. @Description("returns index of first occurrence of a substring (or 0 if not found)")
  2. @ScalarFunction("strpos")
  3. @LiteralParameters({"x", "y"})
  4. @SqlType(StandardTypes.BIGINT)
  5. public static long stringPosition(@SqlType("varchar(x)") Slice string, @SqlType("varchar(y)") Slice substring)
  6. {
  7. if (substring.length() == 0) {
  8. return 1;
  9. }
  10. int index = string.indexOf(substring);
  11. if (index < 0) {
  12. return 0;
  13. }
  14. return countCodePoints(string, 0, index) + 1;
  15. }

代码示例来源:origin: io.airlift/slice

  1. public static void assertIndexOf(Slice data, Slice pattern, int offset, int expected)
  2. {
  3. assertEquals(data.indexOf(pattern, offset), expected);
  4. assertEquals(data.indexOfBruteForce(pattern, offset), expected);
  5. }

代码示例来源:origin: prestodb/presto

  1. private static List<Long> getSyncPositionsBruteForce(RcFileReader recordReader, File file)
  2. {
  3. Slice slice = Slices.allocate((int) file.length());
  4. try (InputStream in = new FileInputStream(file)) {
  5. slice.setBytes(0, in, slice.length());
  6. }
  7. catch (IOException e) {
  8. throw new UncheckedIOException(e);
  9. }
  10. List<Long> syncPositionsBruteForce = new ArrayList<>();
  11. Slice sync = Slices.allocate(SIZE_OF_INT + SIZE_OF_LONG + SIZE_OF_LONG);
  12. sync.setInt(0, -1);
  13. sync.setBytes(SIZE_OF_INT, recordReader.getSync());
  14. long syncPosition = 0;
  15. while (syncPosition >= 0) {
  16. syncPosition = slice.indexOf(sync, (int) syncPosition);
  17. if (syncPosition > 0) {
  18. syncPositionsBruteForce.add(syncPosition);
  19. syncPosition++;
  20. }
  21. }
  22. return syncPositionsBruteForce;
  23. }

代码示例来源:origin: airlift/slice

  1. public static void assertIndexOf(Slice data, Slice pattern, int offset, int expected)
  2. {
  3. assertEquals(data.indexOf(pattern, offset), expected);
  4. assertEquals(data.indexOfBruteForce(pattern, offset), expected);
  5. }

代码示例来源:origin: prestodb/presto

  1. int entryEnd = string.indexOf(entryDelimiter, entryStart);
  2. if (entryEnd >= 0) {
  3. keyValuePair = string.slice(entryStart, entryEnd - entryStart);
  4. int keyEnd = keyValuePair.indexOf(keyValueDelimiter);
  5. if (keyEnd >= 0) {
  6. int valueStart = keyEnd + keyValueDelimiter.length();
  7. Slice value = keyValuePair.slice(valueStart, keyValuePair.length() - valueStart);
  8. if (value.indexOf(keyValueDelimiter) >= 0) {
  9. throw new PrestoException(INVALID_FUNCTION_ARGUMENT, "Key-value delimiter must appear exactly once in each entry. Bad input: '" + keyValuePair.toStringUtf8() + "'");

代码示例来源:origin: airlift/slice

  1. public static void assertIndexOf(Slice data, Slice pattern)
  2. {
  3. int index;
  4. List<Integer> bruteForce = new ArrayList<>();
  5. index = 0;
  6. while (index >= 0 && index < data.length()) {
  7. index = data.indexOfBruteForce(pattern, index);
  8. if (index >= 0) {
  9. bruteForce.add(index);
  10. index++;
  11. }
  12. }
  13. List<Integer> indexOf = new ArrayList<>();
  14. index = 0;
  15. while (index >= 0 && index < data.length()) {
  16. index = data.indexOf(pattern, index);
  17. if (index >= 0) {
  18. indexOf.add(index);
  19. index++;
  20. }
  21. }
  22. assertEquals(bruteForce, indexOf);
  23. }

代码示例来源:origin: prestodb/presto

  1. int entryEnd = string.indexOf(entryDelimiter, entryStart);
  2. if (entryEnd >= 0) {
  3. keyValuePair = string.slice(entryStart, entryEnd - entryStart);
  4. int keyEnd = keyValuePair.indexOf(keyValueDelimiter);
  5. if (keyEnd < 0) {
  6. throw new PrestoException(INVALID_FUNCTION_ARGUMENT, "Key-value delimiter must appear exactly once in each entry. Bad input: " + keyValuePair.toStringUtf8());
  7. Slice key = keyValuePair.slice(0, keyEnd);
  8. Slice value = keyValuePair.slice(valueStart, keyValuePair.length() - valueStart);
  9. if (value.indexOf(keyValueDelimiter) >= 0) {
  10. throw new PrestoException(INVALID_FUNCTION_ARGUMENT, "Key-value delimiter must appear exactly once in each entry. Bad input: " + keyValuePair.toStringUtf8());

代码示例来源:origin: io.airlift/slice

  1. public static void assertIndexOf(Slice data, Slice pattern)
  2. {
  3. int index;
  4. List<Integer> bruteForce = new ArrayList<>();
  5. index = 0;
  6. while (index >= 0 && index < data.length()) {
  7. index = data.indexOfBruteForce(pattern, index);
  8. if (index >= 0) {
  9. bruteForce.add(index);
  10. index++;
  11. }
  12. }
  13. List<Integer> indexOf = new ArrayList<>();
  14. index = 0;
  15. while (index >= 0 && index < data.length()) {
  16. index = data.indexOf(pattern, index);
  17. if (index >= 0) {
  18. indexOf.add(index);
  19. index++;
  20. }
  21. }
  22. assertEquals(bruteForce, indexOf);
  23. }

代码示例来源:origin: prestodb/presto

  1. int matchIndex = string.indexOf(delimiter, previousIndex);

代码示例来源:origin: prestodb/presto

  1. int splitIndex = string.indexOf(delimiter, index);

代码示例来源:origin: prestodb/presto

  1. int indexBuffer = 0;
  2. while (index < str.length()) {
  3. int matchIndex = str.indexOf(search, index);

代码示例来源:origin: airlift/slice

  1. /**
  2. * Returns the index of the first occurrence of the pattern with this slice.
  3. * If the pattern is not found -1 is returned. If patten is empty, zero is
  4. * returned.
  5. */
  6. public int indexOf(Slice slice)
  7. {
  8. return indexOf(slice, 0);
  9. }

代码示例来源:origin: io.airlift/slice

  1. /**
  2. * Returns the index of the first occurrence of the pattern with this slice.
  3. * If the pattern is not found -1 is returned. If patten is empty, zero is
  4. * returned.
  5. */
  6. public int indexOf(Slice slice)
  7. {
  8. return indexOf(slice, 0);
  9. }

代码示例来源:origin: qubole/presto-udfs

  1. private static long stringPosition(Slice string, Slice substring)
  2. {
  3. if (substring.length() == 0) {
  4. return 1L;
  5. }
  6. else {
  7. int index = string.indexOf(substring);
  8. return index < 0 ? 0L : (long) (SliceUtf8.countCodePoints(string, 0, index) + 1);
  9. }
  10. }

代码示例来源:origin: uk.co.nichesolutions.presto/presto-main

  1. @Description("returns index of first occurrence of a substring (or 0 if not found)")
  2. @ScalarFunction("strpos")
  3. @SqlType(StandardTypes.BIGINT)
  4. public static long stringPosition(@SqlType(StandardTypes.VARCHAR) Slice string, @SqlType(StandardTypes.VARCHAR) Slice substring)
  5. {
  6. if (substring.length() == 0) {
  7. return 1;
  8. }
  9. int index = string.indexOf(substring);
  10. if (index < 0) {
  11. return 0;
  12. }
  13. return countCodePoints(string, 0, index) + 1;
  14. }

代码示例来源:origin: prestosql/presto

  1. @Description("returns index of first occurrence of a substring (or 0 if not found)")
  2. @ScalarFunction("strpos")
  3. @LiteralParameters({"x", "y"})
  4. @SqlType(StandardTypes.BIGINT)
  5. public static long stringPosition(@SqlType("varchar(x)") Slice string, @SqlType("varchar(y)") Slice substring)
  6. {
  7. if (substring.length() == 0) {
  8. return 1;
  9. }
  10. int index = string.indexOf(substring);
  11. if (index < 0) {
  12. return 0;
  13. }
  14. return countCodePoints(string, 0, index) + 1;
  15. }

代码示例来源:origin: io.prestosql/presto-rcfile

  1. private static List<Long> getSyncPositionsBruteForce(RcFileReader recordReader, File file)
  2. {
  3. Slice slice = Slices.allocate((int) file.length());
  4. try (InputStream in = new FileInputStream(file)) {
  5. slice.setBytes(0, in, slice.length());
  6. }
  7. catch (IOException e) {
  8. throw new UncheckedIOException(e);
  9. }
  10. List<Long> syncPositionsBruteForce = new ArrayList<>();
  11. Slice sync = Slices.allocate(SIZE_OF_INT + SIZE_OF_LONG + SIZE_OF_LONG);
  12. sync.setInt(0, -1);
  13. sync.setBytes(SIZE_OF_INT, recordReader.getSync());
  14. long syncPosition = 0;
  15. while (syncPosition >= 0) {
  16. syncPosition = slice.indexOf(sync, (int) syncPosition);
  17. if (syncPosition > 0) {
  18. syncPositionsBruteForce.add(syncPosition);
  19. syncPosition++;
  20. }
  21. }
  22. return syncPositionsBruteForce;
  23. }

代码示例来源:origin: prestosql/presto

  1. private static List<Long> getSyncPositionsBruteForce(RcFileReader recordReader, File file)
  2. {
  3. Slice slice = Slices.allocate((int) file.length());
  4. try (InputStream in = new FileInputStream(file)) {
  5. slice.setBytes(0, in, slice.length());
  6. }
  7. catch (IOException e) {
  8. throw new UncheckedIOException(e);
  9. }
  10. List<Long> syncPositionsBruteForce = new ArrayList<>();
  11. Slice sync = Slices.allocate(SIZE_OF_INT + SIZE_OF_LONG + SIZE_OF_LONG);
  12. sync.setInt(0, -1);
  13. sync.setBytes(SIZE_OF_INT, recordReader.getSync());
  14. long syncPosition = 0;
  15. while (syncPosition >= 0) {
  16. syncPosition = slice.indexOf(sync, (int) syncPosition);
  17. if (syncPosition > 0) {
  18. syncPositionsBruteForce.add(syncPosition);
  19. syncPosition++;
  20. }
  21. }
  22. return syncPositionsBruteForce;
  23. }

代码示例来源:origin: io.prestosql/presto-main

  1. @Description("returns index of first occurrence of a substring (or 0 if not found)")
  2. @ScalarFunction("strpos")
  3. @LiteralParameters({"x", "y"})
  4. @SqlType(StandardTypes.BIGINT)
  5. public static long stringPosition(@SqlType("varchar(x)") Slice string, @SqlType("varchar(y)") Slice substring)
  6. {
  7. if (substring.length() == 0) {
  8. return 1;
  9. }
  10. int index = string.indexOf(substring);
  11. if (index < 0) {
  12. return 0;
  13. }
  14. return countCodePoints(string, 0, index) + 1;
  15. }

代码示例来源:origin: com.facebook.presto/presto-rcfile

  1. private static List<Long> getSyncPositionsBruteForce(RcFileReader recordReader, File file)
  2. {
  3. Slice slice = Slices.allocate((int) file.length());
  4. try (InputStream in = new FileInputStream(file)) {
  5. slice.setBytes(0, in, slice.length());
  6. }
  7. catch (IOException e) {
  8. throw new UncheckedIOException(e);
  9. }
  10. List<Long> syncPositionsBruteForce = new ArrayList<>();
  11. Slice sync = Slices.allocate(SIZE_OF_INT + SIZE_OF_LONG + SIZE_OF_LONG);
  12. sync.setInt(0, -1);
  13. sync.setBytes(SIZE_OF_INT, recordReader.getSync());
  14. long syncPosition = 0;
  15. while (syncPosition >= 0) {
  16. syncPosition = slice.indexOf(sync, (int) syncPosition);
  17. if (syncPosition > 0) {
  18. syncPositionsBruteForce.add(syncPosition);
  19. syncPosition++;
  20. }
  21. }
  22. return syncPositionsBruteForce;
  23. }

相关文章