[−][src]Function atm::utils::gen_partition_size
pub fn gen_partition_size(
num_notes: f32,
length: i32,
max_file_count: f32,
partition_depth: i32
) -> u32
Calculate number of MIDI notes per partition.
Arguments
num_notes
: number of possible notes (duplicates allowed)length
: length of generated MIDI sequences (see: gen_sequences)max_file_count
: maximum number of files per partition (recommended <= 4K)partition_depth
: number of partitions
Preconditions
num_notes
> 0length
> 0max_files_count
> 0partition_depth
> 0partition_depth
<=num_notes
- if
num_notes
length
<=max_file_count
,partition_depth
== 1
Examples
let partition_size = atm::utils::gen_partition_size(8.0, 12, 4096.0, 2); // With these parameters, the calculation would be: // https://www.wolframalpha.com/input/?i=ceil%28log64%28max%288%5E12%2F4096%2C+1%29%29%29 assert_eq!(4, partition_size)
Notes:
Most modern filesystems do not perform well with more than 4K files per folder,
and XFS is no exception. In order to prevent overloading a single folder, we decided
to partition sequences by their hash, which is just the integer representation of
the MIDI notes in the sequence (see: libatm::MIDIFile::gen_hash),
such that no folder would contain more than max_file_count
number of files. The formula works as follows:
let N = num_noteslength (number of files to be generated) let D = max(N / max_file_count, 1) (maximum number of directories to generate) let B = num_notespartition_depth (logarithm base) partition_size = ceil(logB(D))
NOTE: If num_notes
is 1 or num_noteslength is less than or equal to
max_file_count
then the function will simply return length
(see Preconditions above).