SHARE
TWEET

Untitled

a guest Jan 19th, 2020 76 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. package org.rsankar.lucenecodecs.mapcodec;
  2.  
  3. import java.io.IOException;
  4.  
  5. import org.apache.lucene.index.Terms;
  6. import org.apache.lucene.index.TermsEnum;
  7. import org.apache.lucene.util.BytesRef;
  8.  
  9. public class ParameterAnalyzer {
  10.   int k;
  11.   int capacity;
  12.   int termCount;
  13.   int distSizeBytes;
  14.  
  15.   public ParameterAnalyzer(Terms terms) throws IOException {
  16.     this.capacity = 1672501;
  17.     this.k = 128;
  18.     this.termCount = countTerms(terms);
  19.     this.distSizeBytes = 1;
  20.   }
  21.  
  22.   public static int getHashcode(long key, int k, int capacity) {
  23.     return (int) ((key * k) % capacity);
  24.   }
  25.  
  26.   public int getHashcode(long key) {
  27.     return getHashcode(key, k, capacity);
  28.   }
  29.  
  30.   private static int countTerms(Terms t) throws IOException {
  31.     TermsEnum te = t.iterator();
  32.     int count = 0;
  33.     while (true) {
  34.       BytesRef term = te.next();
  35.       if (term == null) {
  36.         break;
  37.       }
  38.       ++count;
  39.     }
  40.  
  41.     return count;
  42.   }
  43.  
  44.  
  45. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top