KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > mondrian > rolap > agg > SparseSegmentDataset


1 /*
2 // $Id: //open/mondrian/src/main/mondrian/rolap/agg/SparseSegmentDataset.java#9 $
3 // This software is subject to the terms of the Common Public License
4 // Agreement, available at the following URL:
5 // http://www.opensource.org/licenses/cpl.html.
6 // Copyright (C) 2002-2002 Kana Software, Inc.
7 // Copyright (C) 2002-2007 Julian Hyde and others
8 // All Rights Reserved.
9 // You must accept the terms of that agreement to use this software.
10 //
11 // jhyde, 21 March, 2002
12 */

13 package mondrian.rolap.agg;
14
15 import mondrian.olap.Util;
16 import mondrian.rolap.CellKey;
17
18 import java.util.Map JavaDoc;
19 import java.util.HashMap JavaDoc;
20 import java.util.Iterator JavaDoc;
21
22 /**
23  * A <code>SparseSegmentDataset</code> is a means of storing segment values
24  * which is suitable when few of the combinations of keys have a value present.
25  *
26  * <p>The storage requirements are as follows. Key is 1 word for each
27  * dimension. Hashtable entry is 3 words. Value is 1 word. Total space is (4 +
28  * d) * v. (May also need hash table to ensure that values are only stored
29  * once.)</p>
30  *
31  * <p>NOTE: This class is not synchronized.</p>
32  *
33  * @author jhyde
34  * @since 21 March, 2002
35  * @version $Id: //open/mondrian/src/main/mondrian/rolap/agg/SparseSegmentDataset.java#9 $
36  */

37 class SparseSegmentDataset implements SegmentDataset {
38     private final Map JavaDoc<CellKey, Object JavaDoc> values = new HashMap JavaDoc<CellKey, Object JavaDoc>();
39
40     SparseSegmentDataset(Segment segment) {
41         Util.discard(segment);
42     }
43
44     public Object JavaDoc get(CellKey pos) {
45         return values.get(pos);
46     }
47
48     public void put(CellKey key, Object JavaDoc value) {
49         values.put(key, value);
50     }
51
52     public Iterator JavaDoc<Map.Entry JavaDoc<CellKey, Object JavaDoc>> iterator() {
53         return values.entrySet().iterator();
54     }
55
56     public double getBytes() {
57         // assume a slot, key, and value are each 4 bytes
58
return values.size() * 12;
59     }
60 }
61
62 // End SparseSegmentDataset.java
63
Popular Tags