okami.mom/strata
git clone https://git.nkp.pet/okami.mom/strata
bc6b6f87a
main
1// src/spec/draft_source.cpp - see include/strata/spec/draft_source.hpp. 2#include "strata/spec/draft_source.hpp" 3 4#include <vector> 5 6namespace strata::spec { 7 8std::vector < std::unique_ptr < DraftSource >>& extra_draft_sources () { 9static std::vector < std::unique_ptr < DraftSource >> sources ; 10return sources ; 11} 12 13int propose_from_sources (DraftSource & own ,const int32_t * tail ,int n_tail ,int n_pending ,int max_k ,int min_match , 14int32_t * out ,int * match ,int * source ) { 15* match = 0 ; 16* source = -1 ; 17if (max_k <=0 )return 0 ; 18int best = 0 ; 19 std::vector < int32_t > buf ((size_t )max_k ); 20auto ask = [& ](DraftSource & s ,int index ) { 21int m = 0 ; 22const int k = s .propose (tail ,n_tail ,n_pending ,max_k ,buf .data (),& m ); 23if (k <=0 || m < min_match || m <=* match )return ; 24for (int i = 0 ;i < k && i < max_k ;++ i )out [i ]= buf [(size_t )i ]; 25best = k < max_k ?k :max_k ; 26* match = m ; 27* source = index ; 28 }; 29ask (own ,0 ); 30int index = 1 ; 31for (auto & s :extra_draft_sources ()) 32if (s )ask (* s ,index ++ ); 33return best ; 34} 35 36}// namespace strata::spec