/
SofiMut
/
hashTable
Обзор
Документация
Войти
/
SofiMut
/
hashTable
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
Безопасность
master
LazyString.java
67 строк
2 KB
Софья Степанова
upload files
30 сен 2025, 12:12
30 сен 2025, 12:12
eecb623
Код
Авторство
О чём код?
public class LazyString { private String source; private int start, end; private int hash; private LazyString() { } public LazyString(String source, int start, int end) { this.source = source; this.start = start; this.end = end; StringBuilder pattern = new StringBuilder(); int hash = 0; for (int i = 0; i < length(); i++) { hash += source.charAt(i); pattern.append(source.charAt(i)); } this.hash = hash; } public LazyString shiftRight() { LazyString shifted = new LazyString(); shifted.source = source; shifted.start = start + 1; shifted.end = end + 1; if (end <= shifted.source.length()) { shifted.hash = hash - shifted.source.charAt(start) + shifted.source.charAt(end); } return shifted; } public int length() { return end - start; } public boolean equals(LazyString that) { if (length() != that.length()) { return false; } for (int i = 0; i < length(); i++) { char myChar = source.charAt(start + i); char thatChar = source.charAt(that.start + i); if (myChar != thatChar) { return false; } } return true; } @Override public int hashCode() { return hash; } @Override public boolean equals(Object o) { if (this == o) return true; if (o == null || getClass() != o.getClass()) return false; LazyString that = (LazyString) o; return this.equals(that); } }