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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
use std::collections::hash_map::DefaultHasher;
use std::hash::{Hash, Hasher};
use std::mem::MaybeUninit;
use std::{fmt, marker, mem};

use crate::abitype::{BoxedAbiType, EncodeBoxedAbiType};
use crate::boxed::refs::Gc;
use crate::boxed::*;

const MAX_16BYTE_INLINE_LEN: usize = (16 - 8) / mem::size_of::<Gc<Any>>();
const MAX_32BYTE_INLINE_LEN: usize = (32 - 8) / mem::size_of::<Gc<Any>>();

/// Describes the storage of a set's data
#[derive(Clone, Copy, Debug, PartialEq)]
pub enum SetStorage {
    /// Set data is stored inline in a box of the given size
    Inline(BoxSize),
    /// Set data is stored out-of-line in a 32 byte box
    External,
}

impl SetStorage {
    /// Returns the box size for a set storage
    pub fn box_size(self) -> BoxSize {
        match self {
            SetStorage::Inline(box_size) => box_size,
            SetStorage::External => BoxSize::Size32,
        }
    }
}

/// Immutable set of boxed values
///
/// This is semantically similar to a map of values to the unit type
#[repr(C, align(16))]
pub struct Set<T: Boxed = Any> {
    header: Header,
    inline_len: u32,
    padding: [u8; 24],
    phantom: marker::PhantomData<T>,
}

impl<T: Boxed> Boxed for Set<T> {}

impl<T: Boxed> Set<T> {
    /// Maximum element length of an inline set
    pub const MAX_INLINE_LEN: usize = MAX_32BYTE_INLINE_LEN;

    /// Inline element length used for external sets
    pub const EXTERNAL_INLINE_LEN: u32 = (Self::MAX_INLINE_LEN as u32) + 1;

    /// Constructs a new set with the passed boxed values
    pub fn new(heap: &mut impl AsHeap, values: impl ExactSizeIterator<Item = Gc<T>>) -> Gc<Set<T>> {
        let heap = heap.as_heap_mut();

        // Calculate the hash of our values
        let mut hashed_values: Vec<(u64, Gc<T>)> = values
            .map(|v| {
                let mut state = DefaultHasher::new();
                v.hash_in_heap(heap, &mut state);
                (state.finish(), v)
            })
            .collect();

        // Make the values sorted and unique
        hashed_values.sort_by_key(|(hash, _)| *hash);
        hashed_values
            .dedup_by(|(hash1, v1), (hash2, v2)| hash1 == hash2 && v1.eq_in_heap(heap, v2));

        let storage = Self::storage_for_element_len(hashed_values.len());
        let header = Set::TYPE_TAG.to_heap_header(storage.box_size());

        let boxed = unsafe {
            match storage {
                SetStorage::External => mem::transmute(ExternalSet::new(header, hashed_values)),
                SetStorage::Inline(_) => mem::transmute(InlineSet::new(header, hashed_values)),
            }
        };

        heap.place_box(boxed)
    }

    /// Returns the storage for given element length
    fn storage_for_element_len(len: usize) -> SetStorage {
        const MIN_32BYTE_INLINE_LEN: usize = MAX_16BYTE_INLINE_LEN + 1;

        match len {
            0..=MAX_16BYTE_INLINE_LEN => SetStorage::Inline(BoxSize::Size16),
            MIN_32BYTE_INLINE_LEN..=MAX_32BYTE_INLINE_LEN => SetStorage::Inline(BoxSize::Size32),
            _ => {
                // Too big to fit inline; this needs to be external
                SetStorage::External
            }
        }
    }

    /// Constructs a set by constructing an iterator of values
    pub fn from_values<V, F>(
        heap: &mut impl AsHeap,
        values: impl Iterator<Item = V>,
        cons: F,
    ) -> Gc<Set<T>>
    where
        F: Fn(&mut Heap, V) -> Gc<T>,
    {
        let heap = heap.as_heap_mut();

        let elems: Vec<Gc<T>> = values.map(|v| cons(heap, v)).collect();
        Self::new(heap, elems.into_iter())
    }

    fn is_inline(&self) -> bool {
        self.inline_len <= (Self::MAX_INLINE_LEN as u32)
    }

    fn as_repr(&self) -> Repr<'_, T> {
        if self.is_inline() {
            Repr::Inline(unsafe { &*(self as *const Set<T> as *const InlineSet<T>) })
        } else {
            Repr::External(unsafe { &*(self as *const Set<T> as *const ExternalSet<T>) })
        }
    }

    fn as_repr_mut(&mut self) -> ReprMut<'_, T> {
        if self.is_inline() {
            ReprMut::Inline(unsafe { &mut *(self as *mut Set<T> as *mut InlineSet<T>) })
        } else {
            ReprMut::External(unsafe { &mut *(self as *mut Set<T> as *mut ExternalSet<T>) })
        }
    }

    /// Returns the length of the set
    pub fn len(&self) -> usize {
        match self.as_repr() {
            Repr::Inline(inline) => inline.len(),
            Repr::External(external) => external.len(),
        }
    }

    /// Returns true if the set is empty
    pub fn is_empty(&self) -> bool {
        self.inline_len == 0
    }

    /// Returns true if the passed value is included in the set
    pub fn contains(&self, heap: &Heap, value: &Gc<T>) -> bool {
        match self.as_repr() {
            Repr::Inline(inline) => inline.contains(heap, value),
            Repr::External(external) => external.contains(heap, value),
        }
    }

    /// Returns an iterator over the set
    pub fn iter<'a>(&'a self) -> Box<dyn ExactSizeIterator<Item = Gc<T>> + 'a> {
        // TODO: It would be nice not to box here
        match self.as_repr() {
            Repr::Inline(inline) => Box::new(inline.iter()),
            Repr::External(external) => Box::new(external.iter().copied()),
        }
    }

    /// Returns if this set is a subset of the passed set
    pub fn is_subset(&self, heap: &Heap, other: &Set<T>) -> bool {
        match (self.as_repr(), other.as_repr()) {
            (Repr::External(external_self), Repr::External(external_other)) => {
                // Use optimised external/external logic
                external_self.is_subset(heap, external_other)
            }
            _ => {
                if self.len() > other.len() {
                    return false;
                }

                for self_value in self.iter() {
                    if !other.contains(heap, &self_value) {
                        return false;
                    }
                }

                true
            }
        }
    }
}

impl<T: Boxed> PartialEqInHeap for Set<T> {
    fn eq_in_heap(&self, heap: &Heap, other: &Set<T>) -> bool {
        match (self.as_repr(), other.as_repr()) {
            (Repr::Inline(self_inline), Repr::Inline(other_inline)) => {
                self_inline.eq_in_heap(heap, other_inline)
            }
            (Repr::External(self_external), Repr::External(other_external)) => {
                self_external.eq_in_heap(heap, other_external)
            }
            _ => false,
        }
    }
}

impl<T: Boxed> HashInHeap for Set<T> {
    fn hash_in_heap<H: Hasher>(&self, heap: &Heap, state: &mut H) {
        match self.as_repr() {
            Repr::Inline(inline) => inline.hash_in_heap(heap, state),
            Repr::External(external) => external.hash_in_heap(heap, state),
        }
    }
}

impl<T: Boxed> fmt::Debug for Set<T> {
    fn fmt(&self, formatter: &mut fmt::Formatter<'_>) -> Result<(), fmt::Error> {
        formatter.write_str("Set(")?;
        formatter.debug_list().entries(self.iter()).finish()?;
        formatter.write_str(")")
    }
}

impl<T: Boxed> EncodeBoxedAbiType for Set<T>
where
    T: EncodeBoxedAbiType,
{
    const BOXED_ABI_TYPE: BoxedAbiType = BoxedAbiType::Set(&T::BOXED_ABI_TYPE);
}

#[repr(C, align(16))]
pub struct InlineSet<T: Boxed> {
    header: Header,
    inline_len: u32,
    values: [MaybeUninit<Gc<T>>; MAX_32BYTE_INLINE_LEN],
}

impl<T: Boxed> InlineSet<T> {
    fn new(header: Header, hashed_values: Vec<(u64, Gc<T>)>) -> InlineSet<T> {
        let inline_len = hashed_values.len();

        let mut inline_values = [MaybeUninit::uninit(); MAX_32BYTE_INLINE_LEN];

        for (inline_value, (_, value)) in inline_values.iter_mut().zip(hashed_values) {
            *inline_value = MaybeUninit::new(value);
        }

        InlineSet {
            header,
            inline_len: inline_len as u32,
            values: inline_values,
        }
    }

    fn len(&self) -> usize {
        self.inline_len as usize
    }

    fn iter(&self) -> impl ExactSizeIterator<Item = Gc<T>> + '_ {
        self.values[0..self.inline_len as usize]
            .iter()
            .map(|value| unsafe { value.assume_init() })
    }

    fn contains(&self, heap: &Heap, value: &Gc<T>) -> bool {
        self.iter().any(|v| v.eq_in_heap(heap, value))
    }

    fn eq_in_heap(&self, heap: &Heap, other: &InlineSet<T>) -> bool {
        if self.len() != other.len() {
            return false;
        }

        self.iter()
            .zip(other.iter())
            .all(|(self_value, other_value)| self_value.eq_in_heap(heap, &other_value))
    }

    fn hash_in_heap<H: Hasher>(&self, heap: &Heap, state: &mut H) {
        TypeTag::Set.hash(state);
        state.write_usize(self.len());
        for value in self.iter() {
            value.hash_in_heap(heap, state);
        }
    }
}

#[repr(C, align(16))]
pub struct ExternalSet<T: Boxed> {
    header: Header,
    inline_len: u32,
    sorted_hashed_values: Vec<(u64, Gc<T>)>,
}

impl<T: Boxed> ExternalSet<T> {
    fn new(header: Header, sorted_hashed_values: Vec<(u64, Gc<T>)>) -> ExternalSet<T> {
        ExternalSet {
            header,
            inline_len: Set::<T>::EXTERNAL_INLINE_LEN,
            sorted_hashed_values,
        }
    }

    fn len(&self) -> usize {
        self.sorted_hashed_values.len()
    }

    fn iter(&self) -> impl ExactSizeIterator<Item = &Gc<T>> {
        self.sorted_hashed_values.iter().map(|(_, v)| v)
    }

    fn contains(&self, heap: &Heap, needle_value: &Gc<T>) -> bool {
        // Hash our value
        let mut state = DefaultHasher::new();
        needle_value.hash_in_heap(heap, &mut state);
        let needle_hash = state.finish();

        // Do a binary search for the index
        // This will return an arbitrary matching index if there are multiple matches
        let arbitrary_index = if let Ok(i) = self
            .sorted_hashed_values
            .binary_search_by_key(&needle_hash, |(haystack_hash, _)| *haystack_hash)
        {
            i
        } else {
            return false;
        };

        // Search forwards through hash collisions, including the arbitrary index
        let mut forwards_index = arbitrary_index;
        loop {
            let (hackstack_hash, haystack_value) = self.sorted_hashed_values[forwards_index];

            if hackstack_hash != needle_hash {
                break;
            }
            if haystack_value.eq_in_heap(heap, needle_value) {
                return true;
            }

            forwards_index += 1;
            if forwards_index >= self.sorted_hashed_values.len() {
                break;
            }
        }

        // Search backwards through hash collisions
        let mut backwards_index = arbitrary_index;
        while backwards_index > 0 {
            backwards_index -= 1;
            let (hackstack_hash, haystack_value) = self.sorted_hashed_values[backwards_index];

            if hackstack_hash != needle_hash {
                break;
            }
            if haystack_value.eq_in_heap(heap, needle_value) {
                return true;
            }
        }

        false
    }

    /// Returns if this set is a subset of the passed set
    fn is_subset(&self, heap: &Heap, other: &ExternalSet<T>) -> bool {
        let mut self_iter = self.sorted_hashed_values.iter();
        let mut other_iter = other.sorted_hashed_values.iter();

        loop {
            let (self_hash, self_value) = if let Some(entry) = self_iter.next() {
                entry
            } else {
                // No more elements left to check
                return true;
            };

            // Try to find the element in the other set
            loop {
                let (other_hash, other_value) = if let Some(entry) = other_iter.next() {
                    entry
                } else {
                    // Ran past the end of the other set
                    return false;
                };

                if self_iter.len() > other_iter.len() {
                    // Not enough items remaining in the other set
                    return false;
                } else if other_hash == self_hash && other_value.eq_in_heap(heap, self_value) {
                    // Found corresponding element
                    break;
                } else if other_hash > self_hash {
                    // We've gone past where the corresponding element should be
                    return false;
                }
            }
        }
    }

    fn eq_in_heap(&self, heap: &Heap, other: &ExternalSet<T>) -> bool {
        if self.len() != other.len() {
            return false;
        }

        self.sorted_hashed_values
            .iter()
            .zip(other.sorted_hashed_values.iter())
            .all(|((self_hash, self_value), (other_hash, other_value))| {
                self_hash == other_hash && self_value.eq_in_heap(heap, other_value)
            })
    }

    fn hash_in_heap<H: Hasher>(&self, _: &Heap, state: &mut H) {
        TypeTag::Set.hash(state);
        state.write_usize(self.len());

        // Instead of recursing into values, use their pre-calculated hash
        for (hash, _) in self.sorted_hashed_values.iter() {
            state.write_u64(*hash);
        }
    }
}

enum Repr<'a, T: Boxed> {
    Inline(&'a InlineSet<T>),
    External(&'a ExternalSet<T>),
}

enum ReprMut<'a, T: Boxed> {
    Inline(&'a mut InlineSet<T>),
    External(&'a mut ExternalSet<T>),
}

impl<T: Boxed> Drop for Set<T> {
    fn drop(&mut self) {
        match self.as_repr_mut() {
            ReprMut::Inline(_) => {
                // Do nothing here; we might've been allocated as a 16 byte box so we can't read
                // the whole thing.
            }
            ReprMut::External(external) => unsafe {
                // Call `ExternalSet`'s drop implementation
                ptr::drop_in_place(external);
            },
        }
    }
}

#[cfg(test)]
mod test {
    use super::*;
    use crate::boxed::heap::Heap;
    use std::mem;

    #[test]
    fn sizes() {
        assert_eq!(32, mem::size_of::<Set<Any>>());
        assert_eq!(32, mem::size_of::<InlineSet<Any>>());
        assert_eq!(32, mem::size_of::<ExternalSet<Any>>());
    }

    #[test]
    fn inline_equality() {
        use crate::boxed::Int;

        let mut heap = Heap::empty();

        let boxed1 = Int::new(&mut heap, 1);
        let boxed2 = Int::new(&mut heap, 2);
        let boxed3 = Int::new(&mut heap, 3);

        let forward_set1 = Set::new(&mut heap, IntoIterator::into_iter([boxed1, boxed2, boxed3]));

        let forward_set2 = Set::new(
            &mut heap,
            IntoIterator::into_iter([boxed1, boxed2, boxed2, boxed3]),
        );

        let reverse_set = Set::new(&mut heap, IntoIterator::into_iter([boxed3, boxed2, boxed1]));

        let partial_set = Set::new(&mut heap, IntoIterator::into_iter([boxed1, boxed3]));

        assert!(forward_set1.eq_in_heap(&heap, &reverse_set));
        assert!(forward_set1.eq_in_heap(&heap, &forward_set2));
        assert!(!forward_set1.eq_in_heap(&heap, &partial_set));
    }

    #[test]
    fn inline_contains() {
        use crate::boxed::Int;

        let mut heap = Heap::empty();

        let boxed1 = Int::new(&mut heap, 1);
        let boxed2 = Int::new(&mut heap, 2);
        let boxed3 = Int::new(&mut heap, 3);
        let boxed4 = Int::new(&mut heap, 4);
        let boxed5 = Int::new(&mut heap, 5);

        let empty_set = Set::<Int>::new(&mut heap, std::iter::empty());
        let odd_set = Set::new(&mut heap, IntoIterator::into_iter([boxed1, boxed3, boxed5]));
        let even_set = Set::new(&mut heap, IntoIterator::into_iter([boxed2, boxed4]));

        assert!(!empty_set.contains(&heap, &boxed1));
        assert!(odd_set.contains(&heap, &boxed1));
        assert!(!even_set.contains(&heap, &boxed1));

        assert!(!empty_set.contains(&heap, &boxed2));
        assert!(!odd_set.contains(&heap, &boxed2));
        assert!(even_set.contains(&heap, &boxed2));

        assert!(!empty_set.contains(&heap, &boxed3));
        assert!(odd_set.contains(&heap, &boxed3));
        assert!(!even_set.contains(&heap, &boxed3));
    }

    #[test]
    fn external_equality() {
        use crate::boxed::Int;

        let mut heap = Heap::empty();

        let boxed1 = Int::new(&mut heap, 1);
        let boxed2 = Int::new(&mut heap, 2);
        let boxed3 = Int::new(&mut heap, 3);
        let boxed4 = Int::new(&mut heap, 4);
        let boxed5 = Int::new(&mut heap, 5);

        let forward_set = Set::new(
            &mut heap,
            IntoIterator::into_iter([boxed1, boxed2, boxed3, boxed4, boxed5]),
        );

        let reverse_set = Set::new(
            &mut heap,
            IntoIterator::into_iter([boxed5, boxed4, boxed3, boxed2, boxed1]),
        );

        let inline_set = Set::new(
            &mut heap,
            IntoIterator::into_iter([boxed1, boxed2, boxed3, boxed4]),
        );

        let empty_set = Set::<Int>::new(&mut heap, std::iter::empty());

        assert!(forward_set.eq_in_heap(&heap, &reverse_set));
        assert!(!forward_set.eq_in_heap(&heap, &inline_set));
        assert!(!forward_set.eq_in_heap(&heap, &empty_set));
    }
    #[test]
    fn external_contains() {
        use crate::boxed::Int;

        let mut heap = Heap::empty();

        let boxed1 = Int::new(&mut heap, 1);
        let boxed2 = Int::new(&mut heap, 2);
        let boxed3 = Int::new(&mut heap, 3);
        let boxed4 = Int::new(&mut heap, 4);
        let boxed5 = Int::new(&mut heap, 5);
        let boxed6 = Int::new(&mut heap, 6);
        let boxed7 = Int::new(&mut heap, 7);
        let boxed8 = Int::new(&mut heap, 8);

        let empty_set = Set::<Int>::new(&mut heap, std::iter::empty());

        let odd_set = Set::new(
            &mut heap,
            IntoIterator::into_iter([boxed1, boxed3, boxed5, boxed7]),
        );

        let even_set = Set::new(
            &mut heap,
            IntoIterator::into_iter([boxed2, boxed4, boxed6, boxed8]),
        );

        assert!(!empty_set.contains(&heap, &boxed1));
        assert!(odd_set.contains(&heap, &boxed1));
        assert!(!even_set.contains(&heap, &boxed1));

        assert!(!empty_set.contains(&heap, &boxed2));
        assert!(!odd_set.contains(&heap, &boxed2));
        assert!(even_set.contains(&heap, &boxed2));

        assert!(!empty_set.contains(&heap, &boxed3));
        assert!(odd_set.contains(&heap, &boxed3));
        assert!(!even_set.contains(&heap, &boxed3));
    }

    #[test]
    fn subset() {
        use crate::boxed::Int;

        let mut heap = Heap::empty();

        let boxed1 = Int::new(&mut heap, 1);
        let boxed2 = Int::new(&mut heap, 2);
        let boxed3 = Int::new(&mut heap, 3);
        let boxed4 = Int::new(&mut heap, 4);
        let boxed5 = Int::new(&mut heap, 5);
        let boxed6 = Int::new(&mut heap, 6);
        let boxed7 = Int::new(&mut heap, 7);
        let boxed8 = Int::new(&mut heap, 8);

        let empty_set = Set::<Int>::new(&mut heap, std::iter::empty());
        let one_set = Set::new(&mut heap, IntoIterator::into_iter([boxed1]));
        let odd_set = Set::new(
            &mut heap,
            IntoIterator::into_iter([boxed1, boxed3, boxed5, boxed7]),
        );
        let even_set = Set::new(
            &mut heap,
            IntoIterator::into_iter([boxed2, boxed4, boxed6, boxed8]),
        );
        let full_set = Set::new(
            &mut heap,
            vec![
                boxed1, boxed2, boxed3, boxed4, boxed5, boxed6, boxed7, boxed8,
            ]
            .into_iter(),
        );

        assert!(empty_set.is_subset(&heap, &empty_set));
        assert!(empty_set.is_subset(&heap, &one_set));
        assert!(empty_set.is_subset(&heap, &odd_set));
        assert!(empty_set.is_subset(&heap, &even_set));
        assert!(empty_set.is_subset(&heap, &full_set));

        assert!(!one_set.is_subset(&heap, &empty_set));
        assert!(one_set.is_subset(&heap, &one_set));
        assert!(one_set.is_subset(&heap, &odd_set));
        assert!(!one_set.is_subset(&heap, &even_set));
        assert!(one_set.is_subset(&heap, &full_set));

        assert!(!odd_set.is_subset(&heap, &empty_set));
        assert!(!odd_set.is_subset(&heap, &one_set));
        assert!(odd_set.is_subset(&heap, &odd_set));
        assert!(!odd_set.is_subset(&heap, &even_set));
        assert!(odd_set.is_subset(&heap, &full_set));

        assert!(!even_set.is_subset(&heap, &empty_set));
        assert!(!even_set.is_subset(&heap, &one_set));
        assert!(!even_set.is_subset(&heap, &odd_set));
        assert!(even_set.is_subset(&heap, &even_set));
        assert!(even_set.is_subset(&heap, &full_set));

        assert!(!full_set.is_subset(&heap, &empty_set));
        assert!(!full_set.is_subset(&heap, &one_set));
        assert!(!full_set.is_subset(&heap, &odd_set));
        assert!(!full_set.is_subset(&heap, &even_set));
        assert!(full_set.is_subset(&heap, &full_set));
    }
}