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;