SetAssociativeCacheSidecarImage<DataType extends Object> constructor

SetAssociativeCacheSidecarImage<DataType extends Object>({
  1. required int setCount,
  2. required int wayCount,
  3. required Iterable<int?> tags,
  4. required Iterable<DataType?> payloads,
  5. required Iterable<int> allocatedSlots,
})

Creates a validated set-associative cache image.

Implementation

SetAssociativeCacheSidecarImage({
  required this.setCount,
  required this.wayCount,
  required Iterable<int?> tags,
  required Iterable<DataType?> payloads,
  required Iterable<int> allocatedSlots,
})  : tags = List.unmodifiable(tags),
      payloads = List.unmodifiable(payloads),
      allocatedSlots = Set.unmodifiable(allocatedSlots) {
  if (setCount <= 0 || wayCount <= 0) {
    throw ArgumentError('Set and way counts must be positive.');
  }
  final capacity = setCount * wayCount;
  if (this.tags.length != capacity || this.payloads.length != capacity) {
    throw ArgumentError('Tags and payloads must match cache capacity.');
  }
  if (this.allocatedSlots.any((slot) => slot < 0 || slot >= capacity)) {
    throw ArgumentError('Allocated slot is outside cache capacity.');
  }
  for (final slot in this.allocatedSlots) {
    if (this.tags[slot] == null || this.payloads[slot] == null) {
      throw ArgumentError('Allocated slots must contain tag and payload.');
    }
  }
}