From 0b1e5a2628dedd7af00c23e7384b2ffd7f624ba5 Mon Sep 17 00:00:00 2001 From: ray Date: Wed, 5 Mar 2003 02:51:33 +0000 Subject: [PATCH] Added getKeys() and getValues() which return int[]s. Full revamp of this class pending. git-svn-id: https://samskivert.googlecode.com/svn/trunk@1062 6335cc39-0255-0410-8fd6-9bcaacd3b74c --- .../java/com/samskivert/util/IntIntMap.java | 34 ++++++++++++++++++- 1 file changed, 33 insertions(+), 1 deletion(-) diff --git a/projects/samskivert/src/java/com/samskivert/util/IntIntMap.java b/projects/samskivert/src/java/com/samskivert/util/IntIntMap.java index 99124818..eb6a43e9 100644 --- a/projects/samskivert/src/java/com/samskivert/util/IntIntMap.java +++ b/projects/samskivert/src/java/com/samskivert/util/IntIntMap.java @@ -1,5 +1,5 @@ // -// $Id: IntIntMap.java,v 1.3 2001/08/11 22:43:29 mdb Exp $ +// $Id: IntIntMap.java,v 1.4 2003/03/05 02:51:33 ray Exp $ // // samskivert library - useful routines for java programs // Copyright (C) 2001 Michael Bayne @@ -147,6 +147,38 @@ public class IntIntMap return new Enumerator(_buckets, false); } + /** + * Get an array of the unique keys in this map. + */ + public int[] getKeys () + { + return toIntArray(true); + } + + /** + * Get an array of the values that may be in this map. + * There may be duplicates. + */ + public int[] getValues () + { + return toIntArray(false); + } + + protected int[] toIntArray (boolean keys) + { + int[] ret = new int[_size]; + + int dex = 0; + for (int ii=0, nn=_buckets.length; ii < nn; ii++) { + Record r = _buckets[ii]; + while (r != null) { + ret[dex++] = keys ? r.key : r.value; + r = r.next; + } + } + return ret; + } + class Record { public Record next;