okami.mom/strata
git clone https://git.nkp.pet/okami.mom/strata
bb930bc8b
main
1// The batch window's row layout (include/strata/core/batch_rows.hpp): plain one-row slots, a slot's contiguous group of 2// proposed rows (--batch-mtp), and the hand-off capacity of a layer split's stages. Header-only, CPU. 3#include "strata/core/batch_rows.hpp" 4 5#include <cstdio> 6#include <cstdlib> 7#include <cstring> 8 9namespace { 10int failures = 0 ; 11void check (bool ok ,const char * what ) { 12if (!ok ) { 13 std::fprintf (stderr ,"FAIL: %s\n" ,what ); 14++ failures ; 15 } 16} 17const char * run (const int * rows ,const long long * p ,int S ,int n_slots ,int max_t ,int hbase ,bool handoff ) { 18int64_t pos [8 ]; 19for (int t = 0 ;t < S ;++ t )pos [t ]= p [t ]; 20return strata::core::batch_rows_error (rows ,S ,pos ,n_slots ,max_t ,hbase ,handoff ,8 ); 21} 22}// namespace 23 24int main () { 25using strata::core::batch_rows_error ; 26// plain batch: one row per slot, any positions 27 { 28const int rows []= {0 ,1 ,2 }; 29const long long pos []= {10 ,500 ,3 }; 30check (run (rows ,pos ,3 ,3 ,8 ,0 , false)== nullptr ,"one row per slot" ); 31check (run (rows ,pos ,3 ,3 ,8 ,0 , true)== nullptr ,"one row per slot through the hand-off" ); 32 } 33// --batch-mtp: a slot's two rows at consecutive positions; also on a layer split (S > slots) 34 { 35const int rows []= {1 ,1 ,0 ,0 }; 36const long long pos []= {40 ,41 ,7 ,8 }; 37check (run (rows ,pos ,4 ,2 ,8 ,0 , false)== nullptr ,"two rows per slot, one stage" ); 38check (run (rows ,pos ,4 ,2 ,8 ,0 , true)== nullptr ,"two rows per slot across a layer split (S > slots)" ); 39 } 40// eight rows = four slots of two: the whole hand-off 41 { 42const int rows []= {0 ,0 ,1 ,1 ,2 ,2 ,3 ,3 }; 43const long long pos []= {1 ,2 ,5 ,6 ,9 ,10 ,20 ,21 }; 44check (run (rows ,pos ,8 ,4 ,8 ,0 , true)== nullptr ,"eight rows fill the hand-off" ); 45check (run (rows ,pos ,8 ,4 ,8 ,1 , true)!= nullptr ,"a group past the hand-off's end" ); 46check (run (rows ,pos ,8 ,4 ,8 ,1 , false)== nullptr ,"no hand-off: the base does not bound the rows" ); 47 } 48// refused layouts 49 { 50const int rows []= {0 ,1 ,0 }; 51const long long pos []= {5 ,9 ,6 }; 52check (run (rows ,pos ,3 ,2 ,8 ,0 , false)!= nullptr ,"a slot's rows must be contiguous" ); 53 } 54 { 55const int rows []= {0 ,0 }; 56const long long pos []= {5 ,7 }; 57check (run (rows ,pos ,2 ,1 ,8 ,0 , false)!= nullptr ,"a slot's rows need consecutive positions" ); 58 } 59 { 60const int rows []= {0 ,2 }; 61const long long pos []= {5 ,7 }; 62check (run (rows ,pos ,2 ,2 ,8 ,0 , false)!= nullptr ,"a slot past the slots held" ); 63const int neg []= {-1 }; 64const long long p1 []= {1 }; 65check (run (neg ,p1 ,1 ,2 ,8 ,0 , false)!= nullptr ,"a negative slot" ); 66 } 67 { 68const int rows []= {0 ,0 ,0 }; 69const long long pos []= {1 ,2 ,3 }; 70check (run (rows ,pos ,3 ,1 ,2 ,0 , false)!= nullptr ,"more rows than the window holds" ); 71check (run (rows ,pos ,0 ,1 ,8 ,0 , false)!= nullptr ,"an empty window" ); 72check (run (rows ,pos ,3 ,1 ,8 ,-1 , false)!= nullptr ,"a negative hand-off base" ); 73check (run (rows ,pos ,3 ,1 ,8 ,0 , false)== nullptr ,"three rows of one slot are a group" ); 74 } 75if (failures != 0 )return EXIT_FAILURE ; 76 std::printf ("batch_rows_test: ok\n" ); 77return EXIT_SUCCESS ; 78}