Tue, 11 May 2010 14:35:43 -0700
6931180: Migration to recent versions of MS Platform SDK
6951582: Build problems on win64
Summary: Changes to enable building JDK7 with Microsoft Visual Studio 2010
Reviewed-by: ohair, art, ccheung, dcubed
ysr@777 | 1 | /* |
ysr@777 | 2 | * Copyright 2001-2007 Sun Microsystems, Inc. All Rights Reserved. |
ysr@777 | 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
ysr@777 | 4 | * |
ysr@777 | 5 | * This code is free software; you can redistribute it and/or modify it |
ysr@777 | 6 | * under the terms of the GNU General Public License version 2 only, as |
ysr@777 | 7 | * published by the Free Software Foundation. |
ysr@777 | 8 | * |
ysr@777 | 9 | * This code is distributed in the hope that it will be useful, but WITHOUT |
ysr@777 | 10 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
ysr@777 | 11 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
ysr@777 | 12 | * version 2 for more details (a copy is included in the LICENSE file that |
ysr@777 | 13 | * accompanied this code). |
ysr@777 | 14 | * |
ysr@777 | 15 | * You should have received a copy of the GNU General Public License version |
ysr@777 | 16 | * 2 along with this work; if not, write to the Free Software Foundation, |
ysr@777 | 17 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
ysr@777 | 18 | * |
ysr@777 | 19 | * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, |
ysr@777 | 20 | * CA 95054 USA or visit www.sun.com if you need additional information or |
ysr@777 | 21 | * have any questions. |
ysr@777 | 22 | * |
ysr@777 | 23 | */ |
ysr@777 | 24 | |
ysr@777 | 25 | // This class implements a simple histogram. |
ysr@777 | 26 | |
ysr@777 | 27 | // A histogram summarizes a series of "measurements", each of which is |
ysr@777 | 28 | // assumed (required in this implementation) to have an outcome that is a |
ysr@777 | 29 | // non-negative integer. The histogram efficiently maps measurement outcomes |
ysr@777 | 30 | // to the number of measurements had that outcome. |
ysr@777 | 31 | |
ysr@777 | 32 | // To print the results, invoke print() on your Histogram*. |
ysr@777 | 33 | |
ysr@777 | 34 | // Note: there is already an existing "Histogram" class, in file |
ysr@777 | 35 | // histogram.{hpp,cpp}, but to my mind that's not a histogram, it's a table |
ysr@777 | 36 | // mapping strings to counts. To be a histogram (IMHO) it needs to map |
ysr@777 | 37 | // numbers (in fact, integers) to number of occurrences of that number. |
ysr@777 | 38 | |
ysr@777 | 39 | // ysr: (i am not sure i agree with the above note.) i suspect we want to have a |
ysr@777 | 40 | // histogram template that will map an arbitrary type (with a defined order |
ysr@777 | 41 | // relation) to a count. |
ysr@777 | 42 | |
ysr@777 | 43 | |
ysr@777 | 44 | class IntHistogram : public CHeapObj { |
ysr@777 | 45 | protected: |
ysr@777 | 46 | int _max; |
ysr@777 | 47 | int _tot; |
ysr@777 | 48 | GrowableArray<int>* _elements; |
ysr@777 | 49 | |
ysr@777 | 50 | public: |
ysr@777 | 51 | // Create a new, empty table. "est" is an estimate of the maximum outcome |
ysr@777 | 52 | // that will be added, and "max" is an outcome such that all outcomes at |
ysr@777 | 53 | // least that large will be bundled with it. |
ysr@777 | 54 | IntHistogram(int est, int max); |
ysr@777 | 55 | // Add a measurement with the given outcome to the sequence. |
ysr@777 | 56 | void add_entry(int outcome); |
ysr@777 | 57 | // Return the number of entries recorded so far with the given outcome. |
ysr@777 | 58 | int entries_for_outcome(int outcome); |
ysr@777 | 59 | // Return the total number of entries recorded so far. |
ysr@777 | 60 | int total_entries() { return _tot; } |
ysr@777 | 61 | // Return the number of entries recorded so far with the given outcome as |
ysr@777 | 62 | // a fraction of the total number recorded so far. |
ysr@777 | 63 | double fraction_for_outcome(int outcome) { |
ysr@777 | 64 | return |
ysr@777 | 65 | (double)entries_for_outcome(outcome)/ |
ysr@777 | 66 | (double)total_entries(); |
ysr@777 | 67 | } |
ysr@777 | 68 | // Print the histogram on the given output stream. |
ysr@777 | 69 | void print_on(outputStream* st) const; |
ysr@777 | 70 | }; |