Convert Figma logo to code with AI

g1mv logodensity

Superfast compression library

1,019
47
1,019
0

Top Related Projects

112,250

Windows system utilities to maximize productivity

7,312

A fast and flexible keyboard launcher

24,440

A cross-platform launcher that simply works

A keyboard-driven, vim-like browser based on Python and Qt.

Quick Overview

Density is a Python library for calculating the density of various substances. It provides a simple interface to compute densities for liquids, gases, and solids based on temperature, pressure, and other relevant parameters. The library aims to be a comprehensive tool for scientists, engineers, and students working with material properties.

Pros

  • Easy-to-use API for density calculations
  • Supports a wide range of substances and materials
  • Includes temperature and pressure dependencies for accurate results
  • Well-documented with examples and explanations

Cons

  • Limited to density calculations only, not a full-featured material properties library
  • May require additional data sources for less common substances
  • Accuracy might vary for extreme conditions or complex mixtures

Code Examples

Calculating the density of water at room temperature:

from density import liquid

water_density = liquid.water(temperature=20)
print(f"Density of water at 20°C: {water_density:.2f} kg/m³")

Computing the density of air at different pressures:

from density import gas

air_density_1atm = gas.air(temperature=25, pressure=101325)
air_density_2atm = gas.air(temperature=25, pressure=202650)

print(f"Air density at 1 atm: {air_density_1atm:.4f} kg/m³")
print(f"Air density at 2 atm: {air_density_2atm:.4f} kg/m³")

Determining the density of steel at elevated temperatures:

from density import solid

steel_density_room = solid.steel(temperature=20)
steel_density_hot = solid.steel(temperature=800)

print(f"Steel density at 20°C: {steel_density_room:.2f} kg/m³")
print(f"Steel density at 800°C: {steel_density_hot:.2f} kg/m³")

Getting Started

To use the Density library, first install it using pip:

pip install density

Then, import the desired module and use the appropriate function:

from density import liquid, gas, solid

# Calculate density of water at 30°C
water_density = liquid.water(temperature=30)

# Calculate density of nitrogen at 1 atm and 0°C
nitrogen_density = gas.nitrogen(temperature=0, pressure=101325)

# Calculate density of aluminum at room temperature
aluminum_density = solid.aluminum(temperature=20)

print(f"Water density: {water_density:.2f} kg/m³")
print(f"Nitrogen density: {nitrogen_density:.4f} kg/m³")
print(f"Aluminum density: {aluminum_density:.2f} kg/m³")

This example demonstrates how to calculate densities for different types of substances using the Density library.

Competitor Comparisons

112,250

Windows system utilities to maximize productivity

Pros of PowerToys

  • Extensive suite of productivity tools for Windows users
  • Actively maintained by Microsoft with frequent updates
  • Large community support and user base

Cons of PowerToys

  • Limited to Windows operating system
  • Larger resource footprint due to multiple utilities
  • Steeper learning curve for some advanced features

Code Comparison

PowerToys (C#):

public static string GetFileVersion()
{
    Assembly assembly = Assembly.GetExecutingAssembly();
    return assembly.GetName().Version.ToString();
}

Density (Python):

def get_version():
    return __version__

Summary

PowerToys is a comprehensive toolkit for Windows power users, offering a wide range of utilities to enhance productivity. It benefits from Microsoft's backing and a large community. However, it's limited to Windows and may consume more resources.

Density, on the other hand, is a focused Python project for calculating molecular properties. It's more lightweight and cross-platform but has a narrower scope and smaller community compared to PowerToys.

The code comparison shows PowerToys using C# with more complex version retrieval, while Density uses a simpler Python approach. This reflects the difference in scale and complexity between the two projects.

7,312

A fast and flexible keyboard launcher

Pros of Albert

  • More mature and feature-rich project with a larger community
  • Extensive plugin system for added functionality
  • Cross-platform support (Linux and macOS)

Cons of Albert

  • Heavier resource usage due to more features
  • Steeper learning curve for configuration and customization
  • Larger codebase, potentially more complex for contributors

Code Comparison

Albert (C++):

void MainWidget::show() {
    qApp->setActiveWindow(this);
    window()->show();
    window()->raise();
    window()->activateWindow();
    ui.inputLine->setFocus();
}

Density (Rust):

pub fn show(&mut self) {
    self.window.set_visible(true);
    self.window.set_always_on_top(true);
    self.window.set_focus();
}

Albert uses Qt for its GUI, resulting in more verbose code for window management. Density, being a newer and lighter project, uses a simpler approach with Rust and potentially fewer dependencies.

Both projects aim to provide quick application launchers, but Albert offers a more comprehensive feature set at the cost of complexity, while Density focuses on simplicity and performance. The choice between them depends on user preferences for features versus lightweight operation.

24,440

A cross-platform launcher that simply works

Pros of Wox

  • More mature and feature-rich project with a larger community
  • Supports plugins for extended functionality
  • Cross-platform compatibility (Windows, macOS, Linux)

Cons of Wox

  • Larger codebase, potentially more complex to contribute to
  • Heavier resource usage due to more features

Code Comparison

Wox (C#):

public class Program
{
    public static void Main(string[] args)
    {
        var application = new WoxApp();
        application.Run();
    }
}

Density (Rust):

fn main() {
    let app = density::App::new();
    app.run();
}

Key Differences

  • Wox is written in C# while Density is written in Rust
  • Wox has a more extensive feature set, including plugin support
  • Density appears to be a newer, more lightweight alternative
  • Wox has a larger community and more frequent updates

Use Cases

  • Wox: Ideal for users who need a powerful, customizable launcher with plugin support
  • Density: Better suited for those seeking a minimalist, resource-efficient launcher

Community and Support

  • Wox has a larger user base and more active community support
  • Density is newer and may have less documentation and community resources

A keyboard-driven, vim-like browser based on Python and Qt.

Pros of qutebrowser

  • Mature project with a large community and extensive documentation
  • Feature-rich web browser with keyboard-driven navigation
  • Cross-platform support (Linux, macOS, Windows)

Cons of qutebrowser

  • Steeper learning curve due to its unique keyboard-centric interface
  • Larger codebase and more complex architecture
  • May have higher resource usage compared to lightweight alternatives

Code comparison

qutebrowser (Python):

class BrowserTab(QWidget):
    def __init__(self, win_id, private, parent=None):
        super().__init__(parent)
        self.win_id = win_id
        self.private = private
        self._layout = QVBoxLayout(self)
        self._layout.setContentsMargins(0, 0, 0, 0)
        self._layout.setSpacing(0)

density (JavaScript):

class Tab extends React.Component {
  constructor(props) {
    super(props);
    this.state = {
      url: props.url,
      title: props.title
    };
  }
}

Note: The code comparison is limited due to the significant differences in project scope and implementation languages between qutebrowser and density. qutebrowser is a full-featured web browser, while density appears to be a simpler tab management tool, making a direct code comparison less relevant.

Convert Figma logo designs to code with AI

Visual Copilot

Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.

Try Visual Copilot

README

Density

Superfast compression library

Density is a free, pure rust (formerly C99) open-source compression library.

It is focused on high-speed compression, at the best ratio possible. Density's algorithms are currently at the pareto frontier of compression speed vs ratio (cf. here for an independent benchmark).

Density features a simple API to enable quick integration in any project.

Why is it so fast ?

One of the biggest assets of density is its work unit: unlike most compression algorithms, it is not a byte but a group of 4 bytes.

When other libraries consume one byte of data to apply their algorithmic processing, density consumes 4 bytes.

That's why density's algorithms have been designed from scratch. They cater for 4-byte work units and still provide interesting compression ratios.

Speed pedigree traits

  • 4-byte work units
  • heavy use of registers as opposed to memory
  • avoidance of or use of minimal branching when possible
  • use of low memory data structures to favor processor cache Lx storage
  • library wide inlining

A "blowup protection" is provided, dramatically increasing the processing speed of incompressible input data. The aim is to never exceed original data size, even for incompressible inputs.

Benchmarks

Quick benchmark

Density features an integrated single-core in-memory benchmark.

Just use cargo bench to assess the performance of the library on your platform, as well as lz4's and snappy's, using the dickens file from the renowned silesia corpus.

It is also possible to run the benchmark with your own files, using the following command: FILE=... cargo bench (replace ... with a file path). Popular compression test files include the silesia corpus files or enwik8.

>> Link to a sample run log

Third-party benchmarks

Other benchmarks featuring density (non-exhaustive list) :

  • squash is an abstraction layer for compression algorithms, and has an extremely exhaustive set of benchmark results, including density's, available here.

  • lzbench is an in-memory benchmark of open-source LZ77/LZSS/LZMA compressors.

Build

Density can be built on a number of rust-compatible platforms. First use rustup to install rust.

a) get the source code:

    git clone https://github.com/g1mv/density.git
    cd density

b) build and test:

    cargo build
    cargo test

c) run benchmarks with or without your own files:

    cargo bench
    FILE=... cargo bench

About the algorithms

Density's algorithms are general purpose, very fast algorithms. They empirically exhibit strong performance (pareto frontier speed/ratio) on voluminous datasets and text-based datasets, and are less performant on very small datasets. Their 4-byte work unit approach makes them "slower learners" than Lempel-Ziv-based algorithms, albeit being much faster theoretically.

AlgorithmSpeed rankRatio rankDictionary unit(s)Prediction unit(s)Sig. size (bytes)
chameleon1st3rd108
cheetah2nd2nd218
lion3rd1st256

Chameleon is a dictionary lookup based compression algorithm. It is designed for absolute speed (GB/s order) both for compression and decompression.

Cheetah, developed with inputs from Piotr Tarsa, is derived from chameleon and uses swapped dual dictionary lookups with a single prediction unit.

Lion is derived from chameleon/cheetah. It uses different data structures, dual dictionary lookups and 5 prediction units, giving it a compression ratio advantage on moderate to highly compressible data.

Quick start

Using density in your rust code is a straightforward process.

Include the required dependency in the Cargo.toml file:

[dependencies]
density = "0.16.0"

Use the API:

use std::fs::read;
use density::algorithms::chameleon::chameleon::Chameleon;

fn main() {
    let file_mem = read("file_path").unwrap();

    let mut encoded_mem = vec![0_u8; file_mem.len() << 1];
    let encoded_size = Chameleon::encode(&file_mem, &mut encoded_mem).unwrap();

    let mut decoded_mem = vec![0_u8; file_mem.len() << 1];
    let decoded_size = Chameleon::decode(&encoded_mem[0..encoded_size], &mut decoded_mem).unwrap();
}

And that's it! We've done a compression/decompression round trip with a few lines!