Skip to content

Commit

Permalink
Merge branch '1.21/dev' into 1.21/stable
Browse files Browse the repository at this point in the history
  • Loading branch information
FlashyReese committed Sep 21, 2024
2 parents b42b90a + f348eaf commit 2227436
Show file tree
Hide file tree
Showing 3 changed files with 85 additions and 40 deletions.
2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ val PARCHMENT_VERSION by extra { null }
// https://semver.org/
val MAVEN_GROUP by extra { "me.flashyreese.mods" }
val ARCHIVE_NAME by extra { "reeses-sodium-options" }
val MOD_VERSION by extra { "1.8.0-beta.3" }
val MOD_VERSION by extra { "1.8.0-beta.4" }
val SODIUM_VERSION by extra { "mc1.21-0.6.0-beta.2" }

allprojects {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,12 +59,7 @@ public TabFrame(Dim2i dim, boolean renderOutline, List<Tab<?>> tabs, Runnable on
this.buildFrame();

// Let's build each frame, future note for anyone: do not move this line.
this.tabs.stream().filter(tab -> {
if (this.selectedTab.isEmpty()) {
this.selectedTab.get();
}
return false;
}).forEach(tab -> tab.getFrameFunction().apply(this.frameSection));
this.tabs.stream().filter(tab -> this.selectedTab.filter(value -> value != tab).isPresent()).forEach(tab -> tab.getFrameFunction().apply(this.frameSection));
}

public static Builder createBuilder() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
package me.flashyreese.mods.reeses_sodium_options.util;

import java.text.Normalizer;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;
import java.util.*;
import java.util.function.Function;

public class StringUtils {
Expand Down Expand Up @@ -34,36 +32,6 @@ public static int levenshteinDistance(String a, String b) {
return dp[a.length()][b.length()];
}

// Boyer-Moore exact matching algorithm
public static int boyerMooreSearch(String text, String pattern) {
int m = pattern.length();
int n = text.length();
if (m == 0) return 0;

int[] skip = new int[256];
for (int k = 0; k < 256; k++) {
skip[k] = m;
}
for (int k = 0; k < m - 1; k++) {
skip[pattern.charAt(k)] = m - k - 1;
}

int k = m - 1;
while (k < n) {
int j = m - 1;
int i = k;
while (j >= 0 && text.charAt(i) == pattern.charAt(j)) {
j--;
i--;
}
if (j == -1) {
return i + 1;
}
k += skip[text.charAt(k)];
}
return -1;
}

// Combined search function
public static <T> List<T> searchElements(Iterable<T> elements, String query, Function<T, String> extractSearchableText) {
String normalizedQuery = normalizeText(query);
Expand Down Expand Up @@ -93,4 +61,86 @@ public static <T> List<T> searchElements(Iterable<T> elements, String query, Fun
results.addAll(approxMatches);
return results;
}

// Boyer-Moore with good suffix and bad character heuristics
public static int boyerMooreSearch(String text, String pattern) {
pattern = normalizeText(pattern); // Ensure pattern is normalized too
int patternLength = pattern.length();
int textLength = text.length();

if (patternLength == 0) return 0; // Empty pattern matches at the start of the text

Map<Character, Integer> badCharTable = new HashMap<>();
buildBadCharTable(badCharTable, pattern);

int[] suffixArray = new int[patternLength + 1];
int[] shiftTable = new int[patternLength + 1];
Arrays.fill(shiftTable, 0);

computeFullShiftTable(shiftTable, suffixArray, pattern);
computeGoodSuffixShiftTable(shiftTable, suffixArray, pattern);

int shift = 0;
while (shift <= (textLength - patternLength)) {
int j = patternLength - 1;

while (j >= 0 && pattern.charAt(j) == text.charAt(shift + j)) {
j--;
}

if (j < 0) {
return shift; // Pattern found, return the index
} else {
char mismatchedChar = text.charAt(shift + j);
int badCharShift = badCharTable.getOrDefault(mismatchedChar, -1);
int goodSuffixShift = j + 1 < patternLength ? shiftTable[j + 1] : 1; // Boundary check

shift += Math.max(j - badCharShift, goodSuffixShift);
}
}
return -1; // Pattern not found
}

// Method to build the full suffix shift table
public static void computeFullShiftTable(int[] shiftTable, int[] suffixArray, String pattern) {
int patternLength = pattern.length();
int i = patternLength;
int j = patternLength + 1;
suffixArray[i] = j;

while (i > 0) {
while (j <= patternLength && pattern.charAt(i - 1) != pattern.charAt(j - 1)) {
if (shiftTable[j] == 0) {
shiftTable[j] = j - i;
}
j = suffixArray[j];
}
i--;
j--;
suffixArray[i] = j;
}
}

// Method to compute the good suffix shift table
public static void computeGoodSuffixShiftTable(int[] shiftTable, int[] suffixArray, String pattern) {
int patternLength = pattern.length();
int j = suffixArray[0];

for (int i = 0; i < patternLength; i++) {
if (shiftTable[i] == 0) {
shiftTable[i] = j;
}
if (i == j) {
j = suffixArray[j];
}
}
}

// Method to build the bad character heuristic table
public static void buildBadCharTable(Map<Character, Integer> badCharTable, String pattern) {
int patternLength = pattern.length();
for (int i = 0; i < patternLength - 1; i++) {
badCharTable.put(pattern.charAt(i), i);
}
}
}

0 comments on commit 2227436

Please sign in to comment.