Files
adler32
ansi_term
atty
backtrace
backtrace_sys
bitflags
byteorder
cfg_if
clap
color_quant
crossbeam_deque
crossbeam_epoch
crossbeam_queue
crossbeam_utils
deflate
either
event_loop
failure
failure_derive
float
fnv
gif
gl
graphics
image
inflate
input
interpolation
jpeg_decoder
lazy_static
libc
lzw
memoffset
num
num_cpus
num_derive
num_integer
num_iter
num_rational
num_traits
opengl_graphics
piston
png
rand
rayon
rayon_core
read_color
rustc_demangle
scoped_threadpool
scopeguard
sdl2
sdl2_sys
sdl2_window
serde
serde_derive
shader_version
shaders_graphics2d
colored
textured
sorting_visualization
strsim
synstructure
texture
textwrap
tiff
unicode_width
vec_map
vecmath
viewport
window
 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
//! Different sorting algorithms as well as the general
//! [`Algorithm`](crate::algorithms::Algorithm) trait.

use std::collections::HashMap;

// re-export Array struct for use in algorithms
pub use crate::array::Array;

/// The general trait for all sorting algorithms.
pub trait Algorithm {
  /// Sorts a given [array](crate::array::Array). This method is called in a so
  /// called "algorithm thread".
  fn sort(&self, array: Array);
  /// Returns the name of the algorithm that will be displayed to the user.
  /// Returned value is an owned [String] so it can be generated at runtime.
  fn name(&self) -> String;
}

/// A shorthand macro that declares modules of all algorithms, re-exports those
/// algorithms and generates a function that returns all algorithms.
macro_rules! algorithms {
  ($($id:ident => $type:ident,)+) => {
    $(
      pub mod $id;
      pub use self::$id::$type;
    )*

    /// Returns a [hashmap](HashMap) of all algorithms. It is used in the
    /// [cli](crate::cli) module.
    pub fn all() -> HashMap<String, Box<dyn Algorithm + Send>> {
      let mut algorithms: HashMap<String, Box<dyn Algorithm + Send>> =
        HashMap::new();
      $(algorithms.insert(stringify!($id).to_string(), Box::new(self::$id::$type));)*
      algorithms
    }
  };
}

algorithms![
  bubble => BubbleSort,
  cocktail => CocktailSort,
  cycle => CycleSort,
  gnome => GnomeSort,
  heap => HeapSort,
  insertion => InsertionSort,
  merge => MergeSort,
  quicksort => Quicksort,
  selection => SelectionSort,
  shellsort => Shellsort,
  all => All,
];