001: /*
002: * Primitive Collections for Java.
003: * Copyright (C) 2003 Søren Bak
004: *
005: * This library is free software; you can redistribute it and/or
006: * modify it under the terms of the GNU Lesser General Public
007: * License as published by the Free Software Foundation; either
008: * version 2.1 of the License, or (at your option) any later version.
009: *
010: * This library is distributed in the hope that it will be useful,
011: * but WITHOUT ANY WARRANTY; without even the implied warranty of
012: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
013: * Lesser General Public License for more details.
014: *
015: * You should have received a copy of the GNU Lesser General Public
016: * License along with this library; if not, write to the Free Software
017: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
018: */
019: package bak.pcj.benchmark;
020:
021: import bak.pcj.list.IntList;
022:
023: /**
024: * This class represents a standard data set for benchmarks.
025: * The data set contains three disjoint lists each containing
026: * a range of consecutive int values in shuffled order:
027: * <pre>
028: * shuffle([0 - (size-1)])
029: * shuffle([(size) - (2*size-1)])
030: * shuffle([(2*size) - (3*size-1)])
031: * <pre>
032: *
033: * @author Søren Bak
034: * @version 1.0 2003/5/1
035: * @since 1.0
036: */
037: public class DataSetShuffledCompact extends DataSet {
038:
039: /**
040: * Creates a new shuffled compact data set of a specified
041: * size.
042: *
043: * @param size
044: * the size of the data set to create.
045: *
046: * @throws IllegalArgumentException
047: * if <tt>size</tt> is not positive.
048: */
049: public DataSetShuffledCompact(int size) {
050: super ("Shuffled/Compact/" + size, size);
051: }
052:
053: protected int[] createList(int n, int size) {
054: int[] s = new int[size];
055: int seed;
056: switch (n) {
057: case 0:
058: for (int i = 0; i < size; i++)
059: s[i] = i;
060: seed = 107;
061: break;
062: case 1:
063: for (int i = 0; i < size; i++)
064: s[i] = i + size;
065: seed = 938361;
066: break;
067: case 2:
068: for (int i = 0; i < size; i++)
069: s[i] = i + 2 * size;
070: seed = 53925253;
071: break;
072: default:
073: throw new IllegalArgumentException();
074: }
075: shuffle(s, seed);
076: return s;
077: }
078:
079: /**
080: * Shuffles an int list with a specified random seed value.
081: *
082: * @param list
083: * the list to shuffle.
084: *
085: * @param seed
086: * the random seed to use when shuffling.
087: *
088: * @throws NullPointerException
089: * if <tt>list</tt> is <tt>null</tt>.
090: */
091: private static void shuffle(int[] list, int seed) {
092: java.util.Random rnd = new java.util.Random(seed);
093: int size = list.length;
094: for (int i = 0; i < size; i++) {
095: int idx = rnd.nextInt(size);
096: int tmp = list[i];
097: list[i] = list[idx];
098: list[idx] = tmp;
099: }
100: }
101:
102: }
|