Skip to content

Commit

Permalink
Make stateless helper methods static in SortedPositionLinks
Browse files Browse the repository at this point in the history
  • Loading branch information
pettyjamesm authored and martint committed Nov 4, 2021
1 parent d1e35c1 commit 4b253dd
Showing 1 changed file with 27 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -132,8 +132,20 @@ public Factory build()
}
}

Factory arrayPositionLinksFactory = arrayPositionLinksFactoryBuilder.build();
return createFactory(sortedPositionLinks, arrayPositionLinksFactoryBuilder.build());
}

@Override
public int size()
{
return positionLinks.size();
}

// Separate static method to avoid embedding references to "this"
private static Factory createFactory(int[][] sortedPositionLinks, Factory arrayPositionLinksFactory)
{
requireNonNull(sortedPositionLinks, "sortedPositionLinks is null");
requireNonNull(arrayPositionLinksFactory, "arrayPositionLinksFactory is null");
return new Factory()
{
@Override
Expand All @@ -153,12 +165,6 @@ public long checksum()
}
};
}

@Override
public int size()
{
return positionLinks.size();
}
}

private final PositionLinks positionLinks;
Expand All @@ -176,7 +182,7 @@ private SortedPositionLinks(PositionLinks positionLinks, int[][] sortedPositionL
this.searchFunctions = searchFunctions.stream().toArray(JoinFilterFunction[]::new);
}

private long sizeOfPositionLinks(int[][] sortedPositionLinks)
private static long sizeOfPositionLinks(int[][] sortedPositionLinks)
{
long retainedSize = sizeOf(sortedPositionLinks);
for (int[] element : sortedPositionLinks) {
Expand All @@ -190,6 +196,12 @@ public static FactoryBuilder builder(int size, PagesHashStrategy pagesHashStrate
return new FactoryBuilder(size, pagesHashStrategy, addresses);
}

@Override
public long getSizeInBytes()
{
return sizeInBytes;
}

@Override
public int next(int position, int probePosition, Page allProbeChannelsPage)
{
Expand Down Expand Up @@ -235,7 +247,7 @@ private boolean applyAllSearchFunctions(int buildPosition, int probePosition, Pa
return true;
}

private int findStartPositionForFunction(JoinFilterFunction searchFunction, int[] links, int startOffset, int probePosition, Page allProbeChannelsPage)
private static int findStartPositionForFunction(JoinFilterFunction searchFunction, int[] links, int startOffset, int probePosition, Page allProbeChannelsPage)
{
if (applySearchFunction(searchFunction, links, startOffset, probePosition, allProbeChannelsPage)) {
// MAJOR HACK: if searchFunction is of shape `f(probe) > build_symbol` it is not fit for binary search below,
Expand All @@ -257,7 +269,7 @@ private int findStartPositionForFunction(JoinFilterFunction searchFunction, int[
/**
* Find the first element in position links that is NOT smaller than probePosition
*/
private int lowerBound(JoinFilterFunction searchFunction, int[] links, int first, int last, int probePosition, Page allProbeChannelsPage)
private static int lowerBound(JoinFilterFunction searchFunction, int[] links, int first, int last, int probePosition, Page allProbeChannelsPage)
{
int middle;
int step;
Expand All @@ -276,23 +288,17 @@ private int lowerBound(JoinFilterFunction searchFunction, int[] links, int first
return first;
}

@Override
public long getSizeInBytes()
{
return sizeInBytes;
}

private boolean applySearchFunction(JoinFilterFunction searchFunction, int[] links, int linkOffset, int probePosition, Page allProbeChannelsPage)
private static boolean applySearchFunction(JoinFilterFunction searchFunction, int[] links, int linkOffset, int probePosition, Page allProbeChannelsPage)
{
return applySearchFunction(searchFunction, links[linkOffset], probePosition, allProbeChannelsPage);
return searchFunction.filter(links[linkOffset], probePosition, allProbeChannelsPage);
}

private boolean applySearchFunction(JoinFilterFunction searchFunction, long buildPosition, int probePosition, Page allProbeChannelsPage)
private static boolean applySearchFunction(JoinFilterFunction searchFunction, int buildPosition, int probePosition, Page allProbeChannelsPage)
{
return searchFunction.filter((int) buildPosition, probePosition, allProbeChannelsPage);
return searchFunction.filter(buildPosition, probePosition, allProbeChannelsPage);
}

private static class PositionComparator
private static final class PositionComparator
implements IntComparator
{
private final PagesHashStrategy pagesHashStrategy;
Expand Down

0 comments on commit 4b253dd

Please sign in to comment.