~ubuntu-branches/ubuntu/oneiric/electric/oneiric

« back to all changes in this revision

Viewing changes to com/sun/electric/database/geometry/btree/BTreeTest.java

  • Committer: Bazaar Package Importer
  • Author(s): Onkar Shinde
  • Date: 2010-01-09 16:26:04 UTC
  • mfrom: (1.1.4 upstream) (3.1.6 sid)
  • Revision ID: james.westby@ubuntu.com-20100109162604-1ypvmy8ijmlc6oq7
Tags: 8.10-1
* New upstream version.
* debian/control
  - Add libjava3d-java and quilt build dependencies.
  - Update standards version to 3.8.3.
  - Add libjava3d-java as recommends to binary package.
* debian/rules
  - Use quilt patch system instead of simple patchsys.
  - Add java3d related jar files to DEB_JARS.
* debian/patches/*
  - Update as per current upstream source. Convert to quilt.
* debian/ant.properties
  - Do not disable 3D plugin anymore.
  - Use new property to disable compilation of OS X related classes.
* debian/wrappers/electric
  - Add java3d related jar files to runtime classpath.
* debian/README.source
  - Change text to the appropriate one for quilt.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* -*- tab-width: 4 -*-
 
2
 *
 
3
 * Electric(tm) VLSI Design System
 
4
 *
 
5
 * File: BTreeTest.java
 
6
 *
 
7
 * Copyright (c) 2009 Sun Microsystems and Static Free Software
 
8
 *
 
9
 * Electric(tm) is free software; you can redistribute it and/or modify
 
10
 * it under the terms of the GNU Lesser General Public License as published by
 
11
 * the Free Software Foundation; either version 3 of the License, or
 
12
 * (at your option) any later version.
 
13
 *
 
14
 * Electric(tm) is distributed in the hope that it will be useful,
 
15
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
16
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
17
 * GNU Lesser General Public License for more details.
 
18
 *
 
19
 * You should have received a copy of the GNU Lesser General Public License
 
20
 * along with Electric(tm); see the file COPYING.  If not, write to
 
21
 * the Free Software Foundation, Inc., 59 Temple Place, Suite 330,
 
22
 * Boston, Mass 02111-1307, USA.
 
23
 */
 
24
package com.sun.electric.database.geometry.btree;
 
25
 
 
26
import java.io.*;
 
27
import java.util.*;
 
28
import com.sun.electric.database.geometry.btree.unboxed.*;
 
29
import com.sun.electric.database.geometry.btree.CachingPageStorage.CachedPage;
 
30
 
 
31
/**
 
32
 *  A simple regression test for the BTree.
 
33
 */
 
34
public class BTreeTest {
 
35
    public static void main(String[] s) throws Exception {
 
36
        if (s.length != 4) {
 
37
            System.err.println("");
 
38
            System.err.println("usage: java " + BTree.class.getName() + " <maxsize> <numops> <cachesize> <seed>");
 
39
            System.err.println("");
 
40
            System.err.println("  Creates a BTree and runs random operations on both it and an in-memory TreeMap.");
 
41
            System.err.println("  Reports any disagreements.");
 
42
            System.err.println("");
 
43
            System.err.println("    <maxsize>   maximum number of entries in the tree, or 0 for no limit");
 
44
            System.err.println("    <numops>    number of operations to perform, or 0 for no limit");
 
45
            System.err.println("    <cachesize> number of pages to cache in memory, or 0 for no cache");
 
46
            System.err.println("    <seed>      seed for random number generator, in hex");
 
47
            System.err.println("");
 
48
            System.exit(-1);
 
49
        }
 
50
        Random rand = new Random(Integer.parseInt(s[3], 16));
 
51
        int cachesize = Integer.parseInt(s[2]);
 
52
        int numops = Integer.parseInt(s[1]);
 
53
        int maxsize = Integer.parseInt(s[0]);
 
54
        int size = 0;
 
55
        CachingPageStorage ps = new CachingPageStorageWrapper(FilePageStorage.create(), cachesize, false);
 
56
        BTree<Integer,Integer,Pair<Integer,Integer>> btree =
 
57
            new BTree<Integer,Integer,Pair<Integer,Integer>>(ps, UnboxedInt.instance,
 
58
                                                             UnboxedInt.instance,
 
59
                                                             null,
 
60
                                                             null);
 
61
        TreeMap<Integer,Integer> tm = 
 
62
            new TreeMap<Integer,Integer>();
 
63
 
 
64
        int puts=0, gets=0, deletes=0, misses=0, inserts=0;
 
65
        long lastprint=0;
 
66
 
 
67
        // you can switch one of these off to gather crude performance measurements and compare them to TreeMap
 
68
        boolean do_tm = true;
 
69
        boolean do_bt = true;
 
70
 
 
71
        for(int i=0; numops==0 || i<numops; i++) {
 
72
            if (System.currentTimeMillis()-lastprint > 200) {
 
73
                lastprint = System.currentTimeMillis();
 
74
                System.out.print("\r puts="+puts+" gets="+(gets-misses)+"/"+gets+" deletes="+deletes);
 
75
            }
 
76
            int key = rand.nextInt() % 1000000;
 
77
            switch(rand.nextInt() % 3) {
 
78
                case 0: { // get
 
79
                    Integer tget = do_tm ? tm.get(key) : null;
 
80
                    Integer bget = do_bt ? btree.getValFromKey(key) : null;
 
81
                    gets++;
 
82
                    if (do_tm && do_bt) {
 
83
                        if (tget==null && bget==null) { misses++; break; }
 
84
                        if (tget!=null && bget!=null && tget.equals(bget)) break;
 
85
                        System.out.print("\r puts="+puts+" gets="+(gets-misses)+"/"+gets+" deletes="+deletes);
 
86
                        System.out.println();
 
87
                        System.out.println();
 
88
                        throw new RuntimeException("  disagreement on key " + key + ": btree="+bget+", treemap="+tget);
 
89
                    }
 
90
                    break;
 
91
                }
 
92
 
 
93
                case 1: { // get ordinal
 
94
                    int sz = do_bt ? btree.size() : tm.size();
 
95
                    int ord = sz==0 ? 0 : Math.abs(rand.nextInt()) % sz;
 
96
                    Integer tget = do_tm ? (sz==0 ? null : tm.values().toArray(new Integer[0])[ord]) : null;
 
97
                    Integer bget = do_bt ? btree.getValFromOrd(ord) : null;
 
98
                    gets++;
 
99
                    if (do_tm && do_bt) {
 
100
                        if (tget==null && bget==null) break;
 
101
                        if (tget!=null && bget!=null && tget.equals(bget)) break;
 
102
                        System.out.print("\r puts="+puts+" gets="+(gets-misses)+"/"+gets+" deletes="+deletes);
 
103
                        System.out.println();
 
104
                        System.out.println();
 
105
                        System.out.println("dump:");
 
106
                        throw new RuntimeException("  disagreement on ordinal " + ord + ": btree="+bget+", treemap="+tget);
 
107
                    }
 
108
                    break;
 
109
                }
 
110
 
 
111
                case 2: { // put
 
112
                    int val = rand.nextInt();
 
113
                    boolean already_there = false;
 
114
                    if (do_tm) {
 
115
                        if (do_bt) already_there = tm.get(key)!=null;
 
116
                        tm.put(key, val);
 
117
                    }
 
118
                    if (do_bt) {
 
119
                        if (!do_tm) already_there = btree.getValFromKey(key)!=null;
 
120
                        if (already_there)
 
121
                            btree.replace(key, val);
 
122
                        else
 
123
                            btree.insert(key, val);
 
124
                    }
 
125
                    puts++;
 
126
                    break;
 
127
                }
 
128
 
 
129
                case 3: // delete
 
130
                    deletes++;
 
131
                    break;
 
132
            }
 
133
        }
 
134
    }
 
135
}
 
 
b'\\ No newline at end of file'