public int map(int b, int g, int r) {
        Color c = new Color(r, g, b);
        if (colorHash.containsKey(c)) {
            return colorHash.get(c);
        }
        else {
            double bestdist = Integer.MAX_VALUE;
            int bestpos = 0;
            for(int i = 0; i < numColorsUsed; i+= 3) {
                // smallest distance squared
                double dist = Math.pow(b - colorTab[i], 2);
                dist += Math.pow(g - colorTab[i + 1], 2);
                dist += Math.pow(r - colorTab[i + 2], 2);
                if(dist < bestdist) {
                    bestdist = dist;
                    bestpos = i/3;
                }
            }
            colorHash.put(c, bestpos);
            return bestpos;
        }
    }