Top Description Inners Fields Constructors Methods
org.eclipse.jgit.pgm.debug

pack-priv Class TextHashFunctions

extends TextBuiltin
Class Inheritance
Annotations
@Command
usage:usage_TextHashFunctions
Imports
java.io.File, java.lang.reflect.Field, java.security.MessageDigest, java.util.ArrayList, .Arrays, .HashSet, .List, org.eclipse.jgit.diff.RawText, .RawTextComparator, org.eclipse.jgit.errors.LargeObjectException, org.eclipse.jgit.lib.Constants, .FileMode, .MutableObjectId, .ObjectReader, .Repository, .RepositoryBuilder, .RepositoryCache, org.eclipse.jgit.pgm.Command, .TextBuiltin, org.eclipse.jgit.pgm.internal.CLIText, org.eclipse.jgit.revwalk.RevWalk, org.eclipse.jgit.treewalk.TreeWalk, org.eclipse.jgit.util.FS, .NB, org.kohsuke.args4j.Option

Scan repository to compute maximum number of collisions for hash functions. This is a test suite to help benchmark the collision rate of hash functions when applied to file contents in a Git repository. The test scans all text files in the HEAD revision of the repository it is run within. For each file it finds the unique lines, and then inserts those lines into a hash table to determine collision rates under the selected hash functions. To add another hash function to the test suite, declare a new instance member field of type Hash and implement the hashRegion method. The test suite will automatically pick up the new function through reflection. To add another folding function (method of squashing a 32 bit hash code into the hash tables smaller array index space), declare a new instance field of type Fold and implement the logic. The test suite will automatically pick up the new function through reflection.

Nested and Inner Type Summary

Modifier and TypeClass and Description
private abstract static class
TextHashFunctions.Fold

Base class for any hashCode folding function to be tested.

private static class
private abstract static class
TextHashFunctions.Hash

Base class for any hashCode function to be tested.

private static class
TextHashFunctions.Line

Utility to help us identify unique lines in a file.

Field Summary

Modifier and TypeField and Description
pack-priv final TextHashFunctions.Hash
djb

Professor Daniel J.

pack-priv List<String>
pack-priv List<File>
pack-priv final TextHashFunctions.Fold
golden_ratio

Applies the golden ratio and takes the upper bits.

pack-priv List<String>
pack-priv final TextHashFunctions.Hash
rabin_DeltaIndex

The Rabin polynomial hash that is used by our own DeltaIndex.

pack-priv final TextHashFunctions.Hash
sha1

Standard SHA-1 on the line, using the first 4 bytes as the hash code.

pack-priv final TextHashFunctions.Hash
string_hash31

Hash function commonly used by java.lang.String.

pack-priv int
pack-priv final TextHashFunctions.Fold
truncate

Bitwise-and to extract only the low bits.

Inherited from org.eclipse.jgit.pgm.TextBuiltin:
argWalkdberrserrwgitdirinsoutsoutw

Constructor Summary

AccessConstructor and Description
pack-priv

Method Summary

Modifier and TypeMethod and Description
private static boolean
include(String name, List<String> want)

private List<TextHashFunctions.Function>
init()

protected boolean
requiresRepository()

Overrides org.eclipse.jgit.pgm.TextBuiltin.requiresRepository.

If this command requires a repository.

protected void
run()

Implements abstract org.eclipse.jgit.pgm.TextBuiltin.run.

Perform the actions of this command.

private void
private static int
tableBits(int sz)

private static void
testOne(TextHashFunctions.Function fun, RawText txt, int[] elements, int cnt)

Inherited from org.eclipse.jgit.pgm.TextBuiltin:
containsHelpdiediediedieexecutegetErrorWritergetOutputWritergetRepositorygetResourceBundleinitinitRawparseArgumentsprintUsageprintUsageAndExitprintUsageAndExit

Field Detail

djbback to summary
pack-priv final TextHashFunctions.Hash djb

Professor Daniel J. Bernstein's rather popular string hash.

foldFunctionsback to summary
pack-priv List<String> foldFunctions
Annotations
@Option
name:--fold
metaVar:NAME
usage:Enable fold function(s)
gitDirsback to summary
pack-priv List<File> gitDirs
Annotations
@Option
name:--repository
aliases:-r
metaVar:GIT_DIR
usage:Repository to scan
golden_ratioback to summary
pack-priv final TextHashFunctions.Fold golden_ratio

Applies the golden ratio and takes the upper bits.

hashFunctionsback to summary
pack-priv List<String> hashFunctions
Annotations
@Option
name:--hash
metaVar:NAME
usage:Enable hash function(s)
rabin_DeltaIndexback to summary
pack-priv final TextHashFunctions.Hash rabin_DeltaIndex

The Rabin polynomial hash that is used by our own DeltaIndex.

sha1back to summary
pack-priv final TextHashFunctions.Hash sha1

Standard SHA-1 on the line, using the first 4 bytes as the hash code.

string_hash31back to summary
pack-priv final TextHashFunctions.Hash string_hash31

Hash function commonly used by java.lang.String.

textLimitback to summary
pack-priv int textLimit
Annotations
@Option
name:--text-limit
metaVar:LIMIT
usage:Maximum size in KiB to scan
truncateback to summary
pack-priv final TextHashFunctions.Fold truncate

Bitwise-and to extract only the low bits.

Constructor Detail

TextHashFunctionsback to summary
pack-priv TextHashFunctions()

Method Detail

includeback to summary
private static boolean include(String name, List<String> want)
initback to summary
private List<TextHashFunctions.Function> init()
requiresRepositoryback to summary
protected boolean requiresRepository()

Overrides org.eclipse.jgit.pgm.TextBuiltin.requiresRepository.

Doc from org.eclipse.jgit.pgm.TextBuiltin.requiresRepository.

If this command requires a repository.

Returns:boolean

true if db/getRepository() is required

Annotations
@Override
runback to summary
protected void run() throws Exception

Implements abstract org.eclipse.jgit.pgm.TextBuiltin.run.

Doc from org.eclipse.jgit.pgm.TextBuiltin.run.

Perform the actions of this command.

This method should only be invoked by execute(String[]).

Annotations
@Override
Exceptions
Exception:
an error occurred while processing the command. The main framework will catch the exception and print a message on standard error.
runback to summary
private void run(Repository repo) throws Exception
tableBitsback to summary
private static int tableBits(int sz)
testOneback to summary
private static void testOne(TextHashFunctions.Function fun, RawText txt, int[] elements, int cnt)
org.eclipse.jgit.pgm.debug back to summary

private abstract Class TextHashFunctions.Fold

extends Object
Class Inheritance

Base class for any hashCode folding function to be tested.

Field Summary

Modifier and TypeField and Description
pack-priv String

Constructor Summary

AccessConstructor and Description
private
Fold()

Method Summary

Modifier and TypeMethod and Description
pack-priv abstract int

Returns:

the folded hash, squeezed into only bits.
fold
(int
the 32 bit hash code to be folded into a smaller value.
hash
,
int
total number of bits that can appear in the output. The output value must be in the range [0, 1 << bits). When bits = 2, valid outputs are 0, 1, 2, 3.
bits
)

Fold the given 32-bit hash code into only bits of space.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

nameback to summary
pack-priv String name

Constructor Detail

Foldback to summary
private Fold()

Method Detail

foldback to summary
pack-priv abstract int fold(int hash, int bits)

Fold the given 32-bit hash code into only bits of space.

Parameters
hash:int

the 32 bit hash code to be folded into a smaller value.

bits:int

total number of bits that can appear in the output. The output value must be in the range [0, 1 << bits). When bits = 2, valid outputs are 0, 1, 2, 3.

Returns:int

the folded hash, squeezed into only bits.

org.eclipse.jgit.pgm.debug back to summary

private Class TextHashFunctions.Function

extends Object
Class Inheritance

Field Summary

Modifier and TypeField and Description
pack-priv final TextHashFunctions.Fold
pack-priv final TextHashFunctions.Hash
pack-priv int

Constructor Summary

AccessConstructor and Description
pack-priv

Method Summary

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

foldback to summary
pack-priv final TextHashFunctions.Fold fold
hashback to summary
pack-priv final TextHashFunctions.Hash hash
maxChainLengthback to summary
pack-priv int maxChainLength

Constructor Detail

Functionback to summary
pack-priv Function(TextHashFunctions.Hash cmp, TextHashFunctions.Fold fold)
org.eclipse.jgit.pgm.debug back to summary

private abstract Class TextHashFunctions.Hash

extends RawTextComparator
Class Inheritance

Base class for any hashCode function to be tested.

Field Summary

Modifier and TypeField and Description
pack-priv String
Inherited from org.eclipse.jgit.diff.RawTextComparator:
DEFAULTWS_IGNORE_ALLWS_IGNORE_CHANGEWS_IGNORE_LEADINGWS_IGNORE_TRAILING

Constructor Summary

AccessConstructor and Description
private
Hash()

Method Summary

Modifier and TypeMethod and Description
public boolean
equals(RawText
the first sequence.
a
,
int
item of ai to compare.
ai
,
RawText
the second sequence.
b
,
int
item of bi to compare.
bi
)

Implements abstract org.eclipse.jgit.diff.SequenceComparator.equals.

Compare two items to determine if they are equivalent.

Inherited from org.eclipse.jgit.diff.RawTextComparator:
hashhashRegionreduceCommonStartEnd

Field Detail

nameback to summary
pack-priv String name

Constructor Detail

Hashback to summary
private Hash()

Method Detail

equalsback to summary
public boolean equals(RawText a, int ai, RawText b, int bi)

Implements abstract org.eclipse.jgit.diff.SequenceComparator.equals.

Doc from org.eclipse.jgit.diff.SequenceComparator.equals.

Compare two items to determine if they are equivalent. It is permissible to compare sequence a with itself (by passing a again in position b).

Parameters
a:RawText

the first sequence.

ai:int

item of ai to compare.

b:RawText

the second sequence.

bi:int

item of bi to compare.

Returns:boolean

true if the two items are identical according to this function's equivalence rule.

Annotations
@Override
org.eclipse.jgit.pgm.debug back to summary

private Class TextHashFunctions.Line

extends Object
Class Inheritance

Utility to help us identify unique lines in a file.

Field Summary

Modifier and TypeField and Description
private final int
private final RawText

Constructor Summary

AccessConstructor and Description
pack-priv
Line(RawText txt, int pos)

Method Summary

Modifier and TypeMethod and Description
public boolean
equals(Object
the reference object with which to compare.
obj
)

Overrides java.lang.Object.equals.

Indicates whether some other object is "equal to" this one.

public int
hashCode()

Overrides java.lang.Object.hashCode.

Returns a hash code value for this object.

Inherited from java.lang.Object:
clonefinalizegetClassnotifynotifyAlltoStringwaitwaitwait

Field Detail

posback to summary
private final int pos
txtback to summary
private final RawText txt

Constructor Detail

Lineback to summary
pack-priv Line(RawText txt, int pos)

Method Detail

equalsback to summary
public boolean equals(Object obj)

Overrides java.lang.Object.equals.

Doc from java.lang.Object.equals.

Indicates whether some other object is "equal to" this one.

The equals method implements an equivalence relation on non-null object references:

  • It is reflexive: for any non-null reference value x, x.equals(x) should return true.
  • It is symmetric: for any non-null reference values x and y, x.equals(y) should return true if and only if y.equals(x) returns true.
  • It is transitive: for any non-null reference values x, y, and z, if x.equals(y) returns true and y.equals(z) returns true, then x.equals(z) should return true.
  • It is consistent: for any non-null reference values x and y, multiple invocations of x.equals(y) consistently return true or consistently return false, provided no information used in equals comparisons on the objects is modified.
  • For any non-null reference value x, x.equals(null) should return false.

An equivalence relation partitions the elements it operates on into equivalence classes; all the members of an equivalence class are equal to each other. Members of an equivalence class are substitutable for each other, at least for some purposes.

Parameters
obj:Object

the reference object with which to compare.

Returns:boolean

true if this object is the same as the obj argument; false otherwise.

Annotations
@Override
hashCodeback to summary
public int hashCode()

Overrides java.lang.Object.hashCode.

Doc from java.lang.Object.hashCode.

Returns a hash code value for this object. This method is supported for the benefit of hash tables such as those provided by java.util.HashMap.

The general contract of hashCode is:

  • Whenever it is invoked on the same object more than once during an execution of a Java application, the hashCode method must consistently return the same integer, provided no information used in equals comparisons on the object is modified. This integer need not remain consistent from one execution of an application to another execution of the same application.
  • If two objects are equal according to the equals method, then calling the hashCode method on each of the two objects must produce the same integer result.
  • It is not required that if two objects are unequal according to the equals method, then calling the hashCode method on each of the two objects must produce distinct integer results. However, the programmer should be aware that producing distinct integer results for unequal objects may improve the performance of hash tables.
Returns:int

a hash code value for this object

Annotations
@Override