001    /*
002    // $Id: //open/mondrian/src/main/mondrian/rolap/agg/SparseSegmentDataset.java#9 $
003    // This software is subject to the terms of the Common Public License
004    // Agreement, available at the following URL:
005    // http://www.opensource.org/licenses/cpl.html.
006    // Copyright (C) 2002-2002 Kana Software, Inc.
007    // Copyright (C) 2002-2007 Julian Hyde and others
008    // All Rights Reserved.
009    // You must accept the terms of that agreement to use this software.
010    //
011    // jhyde, 21 March, 2002
012    */
013    package mondrian.rolap.agg;
014    
015    import mondrian.olap.Util;
016    import mondrian.rolap.CellKey;
017    
018    import java.util.Map;
019    import java.util.HashMap;
020    import java.util.Iterator;
021    
022    /**
023     * A <code>SparseSegmentDataset</code> is a means of storing segment values
024     * which is suitable when few of the combinations of keys have a value present.
025     *
026     * <p>The storage requirements are as follows. Key is 1 word for each
027     * dimension. Hashtable entry is 3 words. Value is 1 word. Total space is (4 +
028     * d) * v. (May also need hash table to ensure that values are only stored
029     * once.)</p>
030     *
031     * <p>NOTE: This class is not synchronized.</p>
032     *
033     * @author jhyde
034     * @since 21 March, 2002
035     * @version $Id: //open/mondrian/src/main/mondrian/rolap/agg/SparseSegmentDataset.java#9 $
036     */
037    class SparseSegmentDataset implements SegmentDataset {
038        private final Map<CellKey, Object> values = new HashMap<CellKey, Object>();
039    
040        SparseSegmentDataset(Segment segment) {
041            Util.discard(segment);
042        }
043    
044        public Object get(CellKey pos) {
045            return values.get(pos);
046        }
047    
048        public void put(CellKey key, Object value) {
049            values.put(key, value);
050        }
051    
052        public Iterator<Map.Entry<CellKey, Object>> iterator() {
053            return values.entrySet().iterator();
054        }
055    
056        public double getBytes() {
057            // assume a slot, key, and value are each 4 bytes
058            return values.size() * 12;
059        }
060    }
061    
062    // End SparseSegmentDataset.java