private int maptype1_quantvals(){
    int vals=(int)(Math.floor(Math.pow(entries, 1./dim)));

    // the above *should* be reliable, but we'll not assume that FP is
    // ever reliable when bitstream sync is at stake; verify via integer
    // means that vals really is the greatest value of dim for which
    // vals^b->bim <= b->entries
    // treat the above as an initial guess
    while(true){
      int acc=1;
      int acc1=1;
      for(int i=0; i<dim; i++){
        acc*=vals;
        acc1*=vals+1;
      }
      if(acc<=entries&&acc1>entries){
        return (vals);
      }
      else{
        if(acc>entries){
          vals--;
        }
        else{
          vals++;
        }
      }
    }
  }