1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
#![allow(non_upper_case_globals)]
#![allow(non_camel_case_types)]
#![allow(non_snake_case)]
#![allow(dead_code)]
use std::ptr;
unsafe impl Sync for hand_indexer_s {}
unsafe impl Send for hand_indexer_s {}
include!(concat!(env!("OUT_DIR"), "/bindings.rs"));
static TOTAL_CARDS: &'static [usize; 4] = &[2, 5, 6, 7];
pub type HandIndexer = hand_indexer_s;
pub type HandIndex = hand_index_t;
impl HandIndexer {
pub fn new() -> Self {
Self {
cards_per_round: [0; 8usize],
round_start: [0; 8usize],
rounds: 0,
configurations: [0; 8usize],
permutations: [0; 8usize],
round_size: [0; 8usize],
permutation_to_configuration: [ptr::null_mut(); 8usize],
permutation_to_pi: [ptr::null_mut(); 8usize],
configuration_to_equal: [ptr::null_mut(); 8usize],
configuration: [ptr::null_mut(); 8usize],
configuration_to_suit_size: [ptr::null_mut(); 8usize],
configuration_to_offset: [ptr::null_mut(); 8usize],
}
}
pub fn init(rounds: u32, cards_per_round: Vec<u8>) -> Self {
let mut hand_indexer = HandIndexer::new();
unsafe {
assert!(hand_indexer_init(
rounds.into(),
cards_per_round.as_ptr(),
&mut hand_indexer
));
}
return hand_indexer;
}
pub fn size(&self, round: u32) -> u64 {
return unsafe { hand_indexer_size(self, round.into()) };
}
pub fn get_index(&self, cards: &[u8]) -> HandIndex {
unsafe {
return hand_index_last(self, cards.as_ptr());
}
}
pub fn get_hand(&self, round: u32, index: HandIndex, cards: &mut [u8]) {
unsafe {
hand_unindex(self, round.into(), index, cards.as_mut_ptr());
}
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_index_round_size() {
let preflop_indexer = HandIndexer::init(1, [2].to_vec());
assert_eq!(preflop_indexer.size(0), 169);
let flop_indexer = HandIndexer::init(2, [2, 3].to_vec());
assert_eq!(flop_indexer.size(0), 169);
}
}