-
Notifications
You must be signed in to change notification settings - Fork 107
Expand file tree
/
Copy pathFrequencyTable.java
More file actions
82 lines (66 loc) · 2.69 KB
/
Copy pathFrequencyTable.java
File metadata and controls
82 lines (66 loc) · 2.69 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
/*
* Reference arithmetic coding
*
* Copyright (c) Project Nayuki
* MIT License. See readme file.
* https://www.nayuki.io/page/reference-arithmetic-coding
*/
/**
* A table of symbol frequencies. The table holds data for symbols numbered from 0
* to getSymbolLimit()−1. Each symbol has a frequency, which is a non-negative integer.
* <p>Frequency table objects are primarily used for getting cumulative symbol
* frequencies. These objects can be mutable depending on the implementation.
* The total of all symbol frequencies must not exceed Integer.MAX_VALUE.</p>
*/
public interface FrequencyTable {
/**
* Returns the number of symbols in this frequency table, which is a positive number.
* @return the number of symbols in this frequency table
*/
public int getSymbolLimit();
/**
* Returns the frequency of the specified symbol. The returned value is at least 0.
* @param symbol the symbol to query
* @return the frequency of the symbol
* @throws IllegalArgumentException if the symbol is out of range
*/
public int get(int symbol);
/**
* Sets the frequency of the specified symbol to the specified value.
* The frequency value must be at least 0.
* @param symbol the symbol to set
* @param freq the frequency value to set
* @throws IllegalArgumentException if the frequency is negative or the symbol is out of range
* @throws ArithmeticException if an arithmetic overflow occurs
*/
public void set(int symbol, int freq);
/**
* Increments the frequency of the specified symbol.
* @param symbol the symbol whose frequency to increment
* @throws IllegalArgumentException if the symbol is out of range
* @throws ArithmeticException if an arithmetic overflow occurs
*/
public void increment(int symbol);
/**
* Returns the total of all symbol frequencies. The returned value is at
* least 0 and is always equal to {@code getHigh(getSymbolLimit() - 1)}.
* @return the total of all symbol frequencies
*/
public int getTotal();
/**
* Returns the sum of the frequencies of all the symbols strictly
* below the specified symbol value. The returned value is at least 0.
* @param symbol the symbol to query
* @return the sum of the frequencies of all the symbols below {@code symbol}
* @throws IllegalArgumentException if the symbol is out of range
*/
public int getLow(int symbol);
/**
* Returns the sum of the frequencies of the specified symbol
* and all the symbols below. The returned value is at least 0.
* @param symbol the symbol to query
* @return the sum of the frequencies of {@code symbol} and all symbols below
* @throws IllegalArgumentException if the symbol is out of range
*/
public int getHigh(int symbol);
}