1#![warn(missing_debug_implementations)]
6#![warn(missing_docs)]
7
8use std::collections;
11
12use super::gridbool::Gridbool;
13use super::postrait::PosT;
14
15pub trait SetPos<P: PosT, const WORDS: usize, const SIZE: usize> {
19 fn contains(&self, pos: &P) -> bool;
21 fn insert(&mut self, pos: P);
23 fn remove(&mut self, pos: &P);
25 fn set(&mut self, pos: P, add: bool) {
27 if add {
28 self.insert(pos);
29 } else {
30 self.remove(&pos);
31 }
32 }
33}
34
35impl<P: PosT, const WORDS: usize, const SIZE: usize> SetPos<P, WORDS, SIZE> for Gridbool<P, WORDS> {
36 fn contains(&self, pos: &P) -> bool {
37 self.get(pos)
38 }
39 fn insert(&mut self, pos: P) {
40 self.set_t(&pos)
41 }
42 fn remove(&mut self, pos: &P) {
43 self.set_f(pos)
44 }
45}
46
47impl<P: PosT, const WORDS: usize, const SIZE: usize> SetPos<P, WORDS, SIZE>
48 for collections::HashSet<P>
49where
50 P: Eq + std::hash::Hash,
51{
52 fn contains(&self, pos: &P) -> bool {
53 self.contains(pos)
54 }
55 fn insert(&mut self, pos: P) {
56 self.insert(pos);
57 }
58 fn remove(&mut self, pos: &P) {
59 self.remove(pos);
60 }
61}
62
63impl<P: PosT, const WORDS: usize, const SIZE: usize> SetPos<P, WORDS, SIZE>
64 for collections::BTreeSet<P>
65where
66 P: Ord,
67{
68 fn contains(&self, pos: &P) -> bool {
69 self.contains(pos)
70 }
71 fn insert(&mut self, pos: P) {
72 self.insert(pos);
73 }
74 fn remove(&mut self, pos: &P) {
75 self.remove(pos);
76 }
77}