0

I am looking at a part of code that is used for an IDA* search. When a node is expanded, its child states are then put into the StateCache datastructure, which is a stack as far as I can tell. My question is this: is there any reason one would choose to set the max size of an array to a particular value? The cache data member has a number of elements equal to 10*1024, which seems to me that the cache data member is supposed to only store up to 10 KB (?) of elements, but I am really not sure. What would be the justification for the10*1024 number? Note that I have found this and this stack overflow posts that discuss cache hit/miss w.r.t row-major vs. column-major access of arrays, but these don't answer my question. Also, this code had no comments, otherwise I would've included more.

public class StateCache {
  public static final int MAX_CACHE_SIZE = 10 * 1024;
  int size;
  State[] cache;

  public StateCache() {
    size = 0;
    cache = new State[MAX_CACHE_SIZE];
  }
  
  // push and pop operations
  public State get(State original) {
    if (size > 0) {
      size--;
      State result = cache[size];
      result.init(original);
      return result;
    } else {
      return new State(original);
    }
  }
    
  public void put(State[] children) {
    for (State child: children) {
      if (child == null) {
        return;
      }
      if (size >= MAX_CACHE_SIZE) {
        return;
      }
      cache[size] = child;
      size++;
    }
  }  
}
Jared Frazier
  • 413
  • 1
  • 4
  • 10

0 Answers0