home *** CD-ROM | disk | FTP | other *** search
/ PC Professionell 2007 April / PCpro_2007_04.ISO / files / dsl / jNetTool.exe / org / xbill / DNS / Compression.class (.txt) < prev    next >
Encoding:
Java Class File  |  2005-06-05  |  1.8 KB  |  41 lines

  1. package org.xbill.DNS;
  2.  
  3. class Compression {
  4.    private static final int TABLE_SIZE = 17;
  5.    private Entry[] table = new Entry[17];
  6.    private boolean verbose = Options.check("verbosecompression");
  7.  
  8.    public Compression() {
  9.    }
  10.  
  11.    public void add(int pos, Name name) {
  12.       int row = (name.hashCode() & Integer.MAX_VALUE) % 17;
  13.       Entry entry = new Entry();
  14.       entry.name = name;
  15.       entry.pos = pos;
  16.       entry.next = this.table[row];
  17.       this.table[row] = entry;
  18.       if (this.verbose) {
  19.          System.err.println("Adding " + name + " at " + pos);
  20.       }
  21.  
  22.    }
  23.  
  24.    public int get(Name name) {
  25.       int row = (name.hashCode() & Integer.MAX_VALUE) % 17;
  26.       int pos = -1;
  27.  
  28.       for(Entry entry = this.table[row]; entry != null; entry = entry.next) {
  29.          if (entry.name.equals(name)) {
  30.             pos = entry.pos;
  31.          }
  32.       }
  33.  
  34.       if (this.verbose) {
  35.          System.err.println("Looking for " + name + ", found " + pos);
  36.       }
  37.  
  38.       return pos;
  39.    }
  40. }
  41.