#pragma region CPL License /* Nuclex Native Framework Copyright (C) 2002-2021 Nuclex Development Labs This library is free software; you can redistribute it and/or modify it under the terms of the IBM Common Public License as published by the IBM Corporation; either version 1.0 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the IBM Common Public License for more details. You should have received a copy of the IBM Common Public License along with this library */ #pragma endregion // CPL License #ifndef NUCLEX_STORAGE_COMPRESSION_COMPRESSIONPROVIDER_H #define NUCLEX_STORAGE_COMPRESSION_COMPRESSIONPROVIDER_H #include "Nuclex/Storage/Config.h" #include // for std::size_t #include // for std::vector #include // for std::array // CHECK: Is there a better name for the CompressionProvider class? // CompressionSystem? CompressionManager? CompressionHandler? namespace Nuclex { namespace Storage { namespace Compression { // ------------------------------------------------------------------------------------------- // class CompressionAlgorithm; // ------------------------------------------------------------------------------------------- // /// Provides data compression algorithms class CompressionProvider { /// Initializes a new compression provider with the built-in algorithms public: NUCLEX_STORAGE_API CompressionProvider(); /// Frees all resources owned by the instance public: NUCLEX_STORAGE_API ~CompressionProvider(); /// Counts the number of available compression algorithms /// The number of algorithms known to the compression provider public: NUCLEX_STORAGE_API std::size_t CountAlgorithms() const { return this->algorithms.size(); } /// Accesses the compression algorithm with the specified index /// Index of the compression algorithm that will be accessed /// The compression algorithm with the specified index /// /// Normally, you should use the method to /// directly obtain a compression algorithm that fits your requirements, but if /// you want to access the registered algorithms individually (for example to run /// benchmarks), this method can be helpful. /// public: NUCLEX_STORAGE_API const CompressionAlgorithm &GetAlgorithm( std::size_t index ) const { return *this->algorithms.at(index).get(); } /// Looks up a compression algorithm by its ID /// Unique ID of the compression algorithm /// The compression algorithm with the specified ID /// /// The ID of a compression algorithm can be obtained by calling the /// method. This method is useful if /// you wish to use a specific compression algorithm (i.e. because you need it /// to decompressed existing compressed data or want to compress using /// a specific format for compatibility purposes. /// public: NUCLEX_STORAGE_API const CompressionAlgorithm &GetAlgorithm( const std::array &algorithmId ) const; /// /// Returns the strongest compression algorithm that promises to compress /// the specified amount of data within the specified time /// /// Amount of data that will be compressed /// Time that is available for compression /// /// A compression algorithm fitting the specified performance constraints /// /// /// How fast a compressor can process data depends on the system's performance /// and on the data being compressed, so it is not possible to make an accurate /// prediction for how long a compressor will need in the end. The average performance /// is calculated by running a benchmark, allowing this method to produce somewhat /// realistic estimate on how fast each algorithm would complete. /// public: NUCLEX_STORAGE_API const CompressionAlgorithm &GetOptimalAlgorithm( std::size_t uncompressedDataSize, float compressionTimeSeconds ) const; /// /// Returns the compression algorithm with the strongest compression whose /// time per kilobyte is under than the specified percentile of all known algorithms /// /// /// Performance percentile the requested algorithm should be below /// /// /// The strongest compression algorithm that takes less time then the specified /// percentile of all registered algorithms. /// /// /// /// This method is useful to obtain a strong compression algorithm while filtering out /// any esoteric algorithms that would be extremely slow. Because such algorithms /// reliably explode in processing time, even picking a high percentile, such as /// requiring the compression algorithm to complete in under 90 percent (0.9) of /// the time the slowest algorithm would require, will eliminate the dangerously /// slow ones. /// /// /// You can also use this method to obtain a fast compression algorithm that /// is not merely shoveling uncompressed data by specifying a very low percentile. /// /// public: NUCLEX_STORAGE_API const CompressionAlgorithm &GetStrongAlgorithm( float performanceFactor = 0.75f ) const; /// /// Searches for the strongest compression algorithm that promises to run faster /// than the specified cycle count /// /// /// Highest number of CPU cycles the selected algorithm is allowed to have /// /// /// The strongest algorithm out of those that take less CPU cycles that the specified /// maximum, or the closest one, if all algorithms are too slow /// private: const CompressionAlgorithm &getStrongestAlgorithmFasterThan( std::size_t maximumCyclesPerKilobyte ) const; /// Compression algorithms available for use by the compression provider private: std::vector> algorithms; }; // ------------------------------------------------------------------------------------------- // }}} // namespace Nuclex::Storage::Compression #endif // NUCLEX_STORAGE_COMPRESSION_COMPRESSIONPROVIDER_H