X-Git-Url: https://harrygodden.com/git/?p=csRadar.git;a=blobdiff_plain;f=csrComb.h;h=92a1e0d2fe0bf1c47428b53cd624ea4da824c361;hp=492acdf8c4612015b3312ea1b2bdf348268ff8eb;hb=HEAD;hpb=a97099abba0a239e20929f04ece9d6839c96ac14 diff --git a/csrComb.h b/csrComb.h index 492acdf..92a1e0d 100644 --- a/csrComb.h +++ b/csrComb.h @@ -1,5 +1,38 @@ -#ifndef CSR_COMB_H -#define CSR_COMB_H +// Copyright (C) 2021 Harry Godden (hgn) + +// API +//======================================================================================================================= + +// Algorithm 1: Generate non-repeating combinations of size M in set of N +// Usage: +// int p[3]; +// hgn_comb_init( 3, p ); +// +// do +// { +// something with p[0], p[1], p[2] +// } +// while( hgn_comb( 3, 5, p ) ); +// +// Output of p each iteration: +// 0 1 2 +// 0 1 3 +// 0 1 4 +// 0 2 3 +// 0 2 4 +// 0 3 4 +// 1 2 3 +// 1 2 4 +// 1 3 4 +// 2 3 4 + +void csr_comb_init( int const M, int p[] ); +int csr_comb( int M, int N, int p[] ); + +// Implementation +//======================================================================================================================= + +#ifdef CSR_EXECUTABLE void csr_comb_init( int const M, int p[] ) { @@ -26,14 +59,4 @@ int csr_comb( int M, int N, int p[] ) return 0; } -void csr_comb_print( int M, int p[] ) -{ - for( int i = 0; i < M; i ++ ) - { - printf( "%d ", p[i] ); - } - - printf( "\n" ); -} - #endif