📄 literallysignedminimalperfecthash.java
字号:
package it.unimi.dsi.mg4j.util;/* * MG4J: Managing Gigabytes for Java * * Copyright (C) 2002-2007 Sebastiano Vigna * * This library is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as published by the Free * Software Foundation; either version 2.1 of the License, or (at your option) * any later version. * * This library is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License * for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * */import java.io.IOException;import java.io.UnsupportedEncodingException;import java.lang.reflect.InvocationTargetException;import java.util.Iterator;import com.martiansoftware.jsap.JSAPException;/** Literally signed order-preserving minimal perfect hash tables. * * <P>This class source exemplifies a signed minimal perfect hash table that * signes each term with the term itself, thus avoiding false positives. Note * that it does not feature {@linkplain SignedMinimalPerfectHash#SignedMinimalPerfectHash(String, String, int, boolean) constructors for <samp>gzip</samp>'d files}. * * @author Sebastiano Vigna * @since 0.4 * @deprecated Use the new hashing stuff in Sux4J. */@Deprecatedpublic class LiterallySignedMinimalPerfectHash extends SignedMinimalPerfectHash { private static final long serialVersionUID = 1L; /** An array containing the original strings. */ CharSequence[] signature; /** Creates a new literally signed order-preserving minimal perfect hash table * for the given terms using the given number of weights. * * @param terms some terms to hash; it is assumed that there are * no terms with a common prefix of * <code>weightLength</code> characters. * @param weightLength the number of weights used generating the * intermediate hash functions. * @see MinimalPerfectHash#MinimalPerfectHash(Iterable, int) */ public LiterallySignedMinimalPerfectHash( final Iterable<? extends CharSequence> terms, final int weightLength ) { super( terms, weightLength ); } /** Creates a new literally signed order-preserving minimal perfect hash table for the given * terms, using as many weights as the longest term in the collection. * * @param terms some terms to hash; it is assumed that they do not contain duplicates. * @see MinimalPerfectHash#MinimalPerfectHash(Iterable) * */ public LiterallySignedMinimalPerfectHash( final Iterable<? extends CharSequence> terms ) { super( terms ); } /** Creates a new literally signed order-preserving minimal perfect hash table for the given file * of terms using the given number of weights. * * @param termFile an UTF-8 file containing one term on each line; it is assumed that * it does not contain terms with a common prefix of * <code>weightLength</code> characters. * @param encoding the encoding of <code>wordFile</code>; if <code>null</code>, it * is assumed to be the platform default encoding. * @param weightLength the number of weights used generating the * intermediate hash functions. * @see MinimalPerfectHash#MinimalPerfectHash(String,String,int) */ public LiterallySignedMinimalPerfectHash( final String termFile, final String encoding, final int weightLength ) { super( termFile, encoding, weightLength ); } /** Creates a new literally signed order-preserving minimal perfect hash table for the given file * of terms. * * @param termFile an UTF-8 file containing one term on each line; it is assumed that * it does not contain terms with a common prefix of * <code>weightLength</code> characters. * @param encoding the encoding of <code>wordFile</code>; if <code>null</code>, it * is assumed to be the platform default encoding. * @see MinimalPerfectHash#MinimalPerfectHash(String,String) */ public LiterallySignedMinimalPerfectHash( final String termFile, final String encoding ) { super( termFile, encoding ); } @Override public void initSignatures( final Iterable<? extends CharSequence> terms ) { int i = 0; signature = new CharSequence[ n ]; for ( Iterator<? extends CharSequence> e = terms.iterator(); e.hasNext(); i++ ) signature[ i ] = new MutableString( e.next() ); } @Override public boolean checkSignature( final CharSequence word, final int index ) { if ( n == 0 ) return false; // Empty maps contain no word return signature[ index ].equals( word ); } public boolean checkSignature( final byte[] a, int off, int len, final int index ) { if ( n == 0 ) return false; // Empty maps contain no word try { return signature[ index ].equals( new String( a, off, len, "ISO-8859-1" ) ); } catch ( UnsupportedEncodingException e ) { throw new RuntimeException( e ); } } public static void main( final String[] arg ) throws InstantiationException, IllegalAccessException, InvocationTargetException, NoSuchMethodException, IOException, JSAPException, ClassNotFoundException { MinimalPerfectHash.main( LiterallySignedMinimalPerfectHash.class, arg ); }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -