dict.java
来自「为公司做的质量考核接口源码,用spring,hibernate,XML实现,对X」· Java 代码 · 共 31 行
JAVA
31 行
package com.jr81.source.compression;
import java.util.* ;
// The dictionary
public class Dict {
// mp keeps : Word => Index
// ls keeps : Index => Word
Map mp = new HashMap() ;
List ls = new ArrayList() ;
// Adds an element into the dictionary
public void add(ByteArray str)
{ mp.put(str,new Integer(ls.size())) ;
ls.add(str) ;
}
// Gets the number for the given string.
// If it does not exist, returns -1
public final int numFromStr(ByteArray str)
{ return ( mp.containsKey(str) ?
((Integer)mp.get(str)).intValue() :
-1 ) ; }
// Gets the string for the given number
// If the number does not exist, return null
public final ByteArray strFromNum(int i)
{ return ( i<ls.size() ?
(ByteArray) ls.get(i) :
null ) ; }
public final int size()
{ return ls.size() ; }
} ;
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?