📄 dict.java
字号:
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 + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -