import { promiseVoid } from "../../../shared/src/resolved-promises.js";
import { getSizeOfValue } from "../../../shared/src/size-of-value.js";
import { Visitor } from "../dag/visitor.js";
class GatherNotCachedVisitor extends Visitor {
  #gatheredChunks = /* @__PURE__ */ new Map();
  #gatheredChunksTotalSize = 0;
  #lazyStore;
  #gatherSizeLimit;
  #getSizeOfChunk;
  constructor(dagRead, lazyStore, gatherSizeLimit, getSizeOfChunk = getSizeOfValue) {
    super(dagRead);
    this.#lazyStore = lazyStore;
    this.#gatherSizeLimit = gatherSizeLimit;
    this.#getSizeOfChunk = getSizeOfChunk;
  }
  get gatheredChunks() {
    return this.#gatheredChunks;
  }
  visit(h) {
    if (this.#gatheredChunksTotalSize >= this.#gatherSizeLimit || this.#lazyStore.isCached(h)) {
      return promiseVoid;
    }
    return super.visit(h);
  }
  visitChunk(chunk) {
    if (this.#gatheredChunksTotalSize < this.#gatherSizeLimit) {
      const size = this.#getSizeOfChunk(chunk);
      this.#gatheredChunks.set(chunk.hash, { chunk, size });
      this.#gatheredChunksTotalSize += size;
    }
    return super.visitChunk(chunk);
  }
}
export {
  GatherNotCachedVisitor
};
//# sourceMappingURL=gather-not-cached-visitor.js.map
