Chunk.h 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. /*
  2. * Copyright (c) 2023, Martin Janiczek <martin@janiczek.cz>
  3. *
  4. * SPDX-License-Identifier: BSD-2-Clause
  5. */
  6. #pragma once
  7. #include <AK/Format.h>
  8. #include <AK/String.h>
  9. namespace Test {
  10. namespace Randomized {
  11. // Chunk is a description of a RandomRun slice.
  12. // Used to say which part of a given RandomRun will be shrunk by some
  13. // ShrinkCommand.
  14. //
  15. // For a RandomRun [0,1,2,3,4,5,6,7,8], the Chunk{size=4, index=2} means this:
  16. // [_,_,X,X,X,X,_,_,_]
  17. //
  18. // Different ShrinkCommands will use the Chunk in different ways.
  19. // A few examples:
  20. //
  21. // Original RandomRun: [5,1,3,9,4,2,3,0]
  22. // Chunk we'll show off: [_,_,X,X,X,X,_,_]
  23. //
  24. // ZeroChunk: [5,1,0,0,0,0,3,0]
  25. // SortChunk: [5,1,2,3,4,9,3,0]
  26. // DeleteChunkAndMaybeDecPrevious: [5,1, 3,0]
  27. struct Chunk {
  28. // Possible sizes: 1,2,3,4,8
  29. u8 size = 0;
  30. size_t index = 0;
  31. };
  32. } // namespace Randomized
  33. } // namespace Test
  34. template<>
  35. struct AK::Formatter<Test::Randomized::Chunk> : Formatter<StringView> {
  36. ErrorOr<void> format(FormatBuilder& builder, Test::Randomized::Chunk chunk)
  37. {
  38. return Formatter<StringView>::format(builder, TRY(String::formatted("Chunk<size={}, i={}>", chunk.size, chunk.index)));
  39. }
  40. };