Trait that allows comparing a value to a range of values.

Related tags

Cryptography rust
Overview

range_cmp

Crates.io MIT licensed Apache licensed Build Status

Docs

This Rust crate provides the RangeComparable trait on all types that implement Ord. This traits exposes a rcmp associated method that allows comparing a value with a range of values:

use range_cmp::{RangeComparable, RangeOrdering};
assert_eq!(15.rcmp(20..30), RangeOrdering::Below);
assert_eq!(25.rcmp(20..30), RangeOrdering::Inside);
assert_eq!(35.rcmp(20..30), RangeOrdering::Above);

Empty ranges handling

This crate does not strictly handle empty ranges, which are not mathematically comparable. In this case, range_cmp will show different behavior depending on the representation of the empty range. For instance:

assert_eq!(30.range_cmp(45..35), RangeOrdering::Below);
assert_eq!(30.range_cmp(25..15), RangeOrdering::Above);
assert_eq!(0.range_cmp(0..0), RangeOrdering::Above);
You might also like...
Bitcoin Push Notification Service (BPNS) allows you to receive notifications of Bitcoin transactions of your non-custodial wallets on a provider of your choice, all while respecting your privacy

Bitcoin Push Notification Service (BPNS) Description Bitcoin Push Notification Service (BPNS) allows you to receive notifications of Bitcoin transacti

A mdbook preprocessor that allows the re-usability of template files with dynamic arguments

mdbook-template A mdbook preprocessor that allows the re-usability of template files with dynamic arguments Table of Contents Author Notes Installatio

Allows deploying modules to Aptos under resource accounts.

Aptos Deployer Module containing helpers for deploying resource accounts. Resource accounts allow the module to sign as itself on-chain, which is usef

MevWallet is a smart contract wallet that allows the user to capture MEV from Searchers, or create MEV on purpose.

MevWallet MevWallet is a smart contract wallet that allows the user to capture MEV from Searchers, or create MEV on purpose. This repo contains the so

Lane-Associated Vector (LAV): Portable SIMD vector trait as GAT of SIMD lane trait.

lav Lane-Associated Vector (LAV): Portable SIMD vector trait as GAT of SIMD lane trait. NOTE: This crate requires nightly Rust. Provides SIMD lane tra

A lending iterator trait based on generic associated types and higher-rank trait bounds

A lending iterator trait based on higher-rank trait bounds (HRTBs) A lending iterator is an iterator which lends mutable borrows to the items it retur

Web-based tool that allows browsing and comparing symbol and type information of Microsoft Windows binaries across different versions of the OS.
Web-based tool that allows browsing and comparing symbol and type information of Microsoft Windows binaries across different versions of the OS.

WinDiff About WinDiff is an open-source web-based tool that allows browsing and comparing symbol and type information of Microsoft Windows binaries ac

LevelDB is a fast key-value storage library written at Google that provides an ordered mapping from string keys to string values.

LevelDB is a fast key-value storage library written at Google that provides an ordered mapping from string keys to string values. Authors: Sanjay Ghem

This shows proof-of-concept implementation of lexer-parser-evaluator which allows setting custom values to keywords.

Custom Configurable Lexer-Parser Note This is still very experimental, and for any syntax error it will just panic giving very unhelpful error message

General basic key-value structs for Key-Value based storages

General basic key-value structs for Key-Value based storages

An inquiry into nondogmatic software development. An experiment showing double performance of the code running on JVM comparing to equivalent native C code.
An inquiry into nondogmatic software development. An experiment showing double performance of the code running on JVM comparing to equivalent native C code.

java-2-times-faster-than-c An experiment showing double performance of the code running on JVM comparing to equivalent native C code ⚠️ The title of t

A library for comparing data structures in Rust, oriented toward testing

Delta: Structural differencing in Rust The delta crate defines the trait Delta, along with a derive macro for auto-generating instances of this trait

A library for comparing data structures in Rust, oriented toward testing

The comparable crate defines the trait [Comparable], along with a derive macro for auto-generating instances of this trait for most data types. Primar

Code for comparing CDN speeds!

How to run speed test. the image to use The image you should probably use is: cf_219kb.png cf_219kb.png is an image that won't be compressed by Jetpac

Benchmark tool for comparing with other runtimes.

Monoio Benchmark TCP ping-pong(not echo) is a common benchmark for network applications. We will use 1K ping-pong to test performance of different run

Comparing performance of Rust math libraries for common 3D game and graphics tasks

mathbench mathbench is a suite of unit tests and benchmarks comparing the output and performance of a number of different Rust linear algebra librarie

Multi-stream HTTP downloader using range requests

chooch - An Amazing Project Downloads files faster than wget/curl (in theory) using multiple connections. Chooch recycles the slowest connection and r

 An iterator following a space-filling pattern over a given range
An iterator following a space-filling pattern over a given range

rlp-iter rlp-iter (Resolving Lattice Point Iterator) is an iterator that returns a space-filling permutation of integers in a given range. Specificall

ZKP fork for rust-secp256k1, adds wrappers for range proofs, pedersen commitments, etc

rust-secp256k1 rust-secp256k1 is a wrapper around libsecp256k1, a C library by Peter Wuille for producing ECDSA signatures using the SECG curve secp25

Comments
  • Support values that are only `PartialOrd`

    Support values that are only `PartialOrd`

    Excluding the empty range case, handling Ord values is pretty straightforward. However, implementing range comparison with only PartialOrd is non-trivial.

    As a simple non-total partial order, we can use the relation “divides”. For instance, 2 divides 6 and 3 divides 6, but 4 does not divide 6. This is a partial order because:

    • reflexivity: for any natural integer (including 0) x, x divides x
    • antisymmetry: for any natural integers x and y, if x divides y and y divides x, then x = y (it follows naturally from the fact that, if x divides y, then xy)
    • transitivity: for any natural integers x, y and z, if x divides y and y divides z, then x divides z

    However, this is not a total order, because 4 does not divide 6 and 6 does not divide 4.

    Now, given x, y and z that implement the PartialOrd describe above, what should the relation between x and y..z be? Note that, by definition, y..z contains all a such that verify: x divides a and a divides z. Let us consider a few cases:

    1. with 4 and 2..8 : since 2 divides 4 and 4 divides 8, the result is clearly Inside
    2. with 2 and 4..8 : since 2 divides 4, the result is clearly Below
    3. with 8 and 2..4 : since 4 divides 8, the result is clear Above
    4. with 3 and 2..8 : since 3 is not in the interval 2..8, it should not be considered Inside for this order
    5. with 3 and 4..8 : since 3 does not divide any element of 4..8, we cannot say that it is Below for this order
    6. with 9 and 2..4 : since no element of 2..4 divide 9, we cannot say that it is Above for this order

    Now, the mathematical definition is valid when y divides z. But Rust's range types do not enforce this, so we have an additional case to handle:

    1. with 4 and 2..7 : 2 does not divide 7, so it is not covered by the definition

    And finally, #6 applies as well:

    1. with 4 and 8..2 : the interval is empty, so comparison is meaningless

    Cases 1, 2, 3 are open-and-shut. I think 4 through 8 should return None as per PartialOrd semantics. 8 is more debatable.

    opened by qsantos 0
  • [Major] Rename range_cmp -> rcmp

    [Major] Rename range_cmp -> rcmp

    The goal of this PR is to prepare for the introduction of range comparison for partial orders: PartialRangeOrd.

    Hence this PR introduces the following major changes:

    • The RangeComparable trait is renamed RangeOrd to align with the standard lib's naming convention and ensure consistent and simple naming.
    • Its exposed method, range_cmp, is renamed rcmp to lay grounds for the upcoming partial range comparison case.

    Description of commits:

    1. Upgrade version to 0.2.0
    2. Rename range_cmp -> rcmp
    3. Rename RangeComparable -> RangeOrd
    opened by adriendellagaspera 0
  • Introduce range comparison for `PartialOrd`

    Introduce range comparison for `PartialOrd`

    The goal of this PR is to introduce Range comparison for partial orders: PartialRangeOrd.

    Hence this PR introduces the following features:

    • The PartialRangeOrd trait, exposing the partial_rcmp method,
    • A generic implementation for any type that implements PartialOrd.

    Description of commits:

    1. Introduce PartialRangeOrd
    2. Add tests
    opened by adriendellagaspera 0
  • Fix handling of empty range

    Fix handling of empty range

    Currently, comparing a value to the empty set yields different results, depending on how it is represented:

            assert_eq!(30.range_cmp(45..35), RangeOrdering::Below);
            assert_eq!(30.range_cmp(25..15), RangeOrdering::Above);
    

    If we want to follow the semantics of the set of values represented by the range, none of these is actually correct, and we should add a new variant for RangeOrdering for this case.

    We could also decide that we want to keep this behavior, since the representations 45..35 and 25..15 actually represent different objects.

    opened by qsantos 1
Owner
Akvize
Faire du conseil autrement. Radicalement.
Akvize
Bulletproofs and Bulletproofs+ Rust implementation for Aggregated Range Proofs over multiple elliptic curves

Bulletproofs This library implements Bulletproofs+ and Bulletproofs aggregated range proofs with multi-exponent verification. The library supports mul

[ZenGo X] 62 Dec 13, 2022
Hash trait that is object-safe

Hash trait that is object-safe This crate provides a DynHash trait that can be used in trait objects. Types that implement the standard library's std:

David Tolnay 19 Nov 12, 2023
Manage secret values in-repo via public key cryptography

amber Manage secret values in-repo via public key cryptography. See the announcement blog post for more motivation. Amber provides the ability to secu

FP Complete 82 Nov 10, 2022
A value transfer bridge between the Monero blockchain and the Secret Network.

Secret-Monero-Bridge A value transfer bridge between the Monero blockchain and the Secret Network. Proof-of-Concept Video Demonstration: https://ipfs.

null 28 Dec 7, 2022
A rust binding for nodejs to generate md5 hash value

Hasher A rust binding for creating node module to generate md5 hash value This project was bootstrapped by create-neon. Installing hasher Installing h

Md. Al-Amin 0 Nov 7, 2021
AMCOS - A high-peformance parallel monte-carlo simulation for estimating the fair value of options in finance

antoons-monte-carlo-options-sim A high-peformance parallel monte-carlo simulation for estimating the fair value of options in finance. Written in Rust

null 4 Jun 18, 2022
Sparse Merkle tree for a key-value map.

LSMTree A Rust library that implements a Sparse Merkle tree for a key-value store. The tree implements the same optimisations specified in the Libra w

Al Liu 14 Oct 8, 2022
A simple key-value store with a log-structured, append-only storage architecture where data is encrypted with AES GCM.

akvdb A simple key-value store with a log-structured, append-only storage architecture where data is encrypted with AES GCM. Modified from the actionk

Olle W 3 Oct 10, 2022
A CLI application which allows you to archive Urbit channels and all linked content in them.

The Urbit Content Archiver is a small CLI application that exports channels from your Urbit ship and auto-downloads any directly linked content locall

Robert Kornacki 33 Sep 25, 2022
Metaplex is a protocol built on top of Solana that allows: Creating/Minting non-fungible tokens;

Metaplex is a protocol built on top of Solana that allows: Creating/Minting non-fungible tokens; Starting a variety of auctions for primary/secondary

Metaplex Foundation 3.2k Jan 4, 2023