/* DefaultVobMatcher.java * * Copyright (c) 2002, Tuomas J. Lukka * * You may use and distribute under the terms of either the GNU Lesser * General Public License, either version 2 of the license or, * at your choice, any later version. Alternatively, you may use and * distribute under the terms of the XPL. * * See the LICENSE.lgpl and LICENSE.xpl files for the specific terms of * the licenses. * * This software 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 README * file for more details. * */ /* * Written by Tuomas J. Lukka */ package gzz.vob; import java.awt.*; import java.util.*; public class DefaultVobMatcher implements VobMatcher { public static boolean dbg = false; private static void pa(String s) { System.err.println(s); } Object[] keys = new Object[10000]; HashMap inds = new HashMap(); int maxcs = 0; static public int mix(int i1, int i2, int i3) { return (i1 * 5124723 + 9812375) % 5350917 + (i2 * 127401 + 897124) % 1128501 + (i3 * 317819 + 1897124) % 12501 ; } // --- implement VobMatcher public void add(int cs, Object key) { if(cs > maxcs) maxcs = cs; keys[cs] = key; if(key!=null) inds.put(key, new Integer(cs)); } public void addSub(int into, int cs, Object key) { // Create a new key in a somewhat silly way // a REAL kludge if(dbg) pa("Passed key: "+key); key = new Integer( mix(key.hashCode(), keys[into] != null ? 1 : 0, keys[into] != null ? keys[into].hashCode() : 0)); if(dbg) { pa("Old key: "+keys[into]); pa("New key: "+key); } add(cs, key); } public int getCS(Object key) { Integer i = (Integer)inds.get(key); if(i==null) return -1; return i.intValue(); } public Object getKey(int cs) { return keys[cs]; } public int[] interpList(VobMatcher other) { int[] interpList = new int[maxcs]; for(int i=0; i