All Projects → zbraniecki → Tinystr

zbraniecki / Tinystr

Licence: other
A small ASCII-only bounded length string representation.

Programming Languages

rust
11053 projects

Projects that are alternatives of or similar to Tinystr

Reflective Bind
Eliminate wasteful re-rendering in React components caused by inline functions
Stars: ✭ 366 (+662.5%)
Mutual labels:  performance, optimization
Solid
🎯 A comprehensive gradient-free optimization framework written in Python
Stars: ✭ 546 (+1037.5%)
Mutual labels:  library, optimization
Awesome Wp Speed Up
Plugins and resources to speed up and optimize your WordPress site.
Stars: ✭ 375 (+681.25%)
Mutual labels:  performance, optimization
Str
A fast, solid and strong typed string manipulation library with multibyte support
Stars: ✭ 199 (+314.58%)
Mutual labels:  library, string
Casadi
CasADi is a symbolic framework for numeric optimization implementing automatic differentiation in forward and reverse modes on sparse matrix-valued computational graphs. It supports self-contained C-code generation and interfaces state-of-the-art codes such as SUNDIALS, IPOPT etc. It can be used from C++, Python or Matlab/Octave.
Stars: ✭ 714 (+1387.5%)
Mutual labels:  library, optimization
Onednn
oneAPI Deep Neural Network Library (oneDNN)
Stars: ✭ 2,600 (+5316.67%)
Mutual labels:  library, performance
Ustring
The Hoa\Ustring library.
Stars: ✭ 403 (+739.58%)
Mutual labels:  library, string
Geotic
Entity Component System library for javascript
Stars: ✭ 97 (+102.08%)
Mutual labels:  library, performance
Tiramisu
A polyhedral compiler for expressing fast and portable data parallel algorithms
Stars: ✭ 685 (+1327.08%)
Mutual labels:  library, optimization
Pydis
A redis clone in Python 3 to disprove some falsehoods about performance.
Stars: ✭ 623 (+1197.92%)
Mutual labels:  performance, optimization
Tracy
C++ frame profiler
Stars: ✭ 3,115 (+6389.58%)
Mutual labels:  library, performance
Php Confusable Homoglyphs
A PHP port of https://github.com/vhf/confusable_homoglyphs
Stars: ✭ 27 (-43.75%)
Mutual labels:  library, string
Validatetor
Android library for fast and simple string validation
Stars: ✭ 136 (+183.33%)
Mutual labels:  library, string
Ristretto
A high performance memory-bound Go cache
Stars: ✭ 3,584 (+7366.67%)
Mutual labels:  library, performance
Xseries
Library for cross-version Minecraft Bukkit support and various efficient API methods.
Stars: ✭ 109 (+127.08%)
Mutual labels:  library, performance
Linux Steam Integration
Helper for enabling better Steam integration on Linux
Stars: ✭ 386 (+704.17%)
Mutual labels:  library, performance
Awesome Go Perf
A curated list of Awesome Go performance libraries and tools
Stars: ✭ 223 (+364.58%)
Mutual labels:  performance, optimization
D2dlib
A .NET library for hardware-accelerated, high performance, immediate mode rendering via Direct2D.
Stars: ✭ 84 (+75%)
Mutual labels:  library, performance
Chillout
Reduce CPU usage by non-blocking async loop and psychologically speed up in JavaScript
Stars: ✭ 565 (+1077.08%)
Mutual labels:  performance, optimization
Stringplus
Funny and minimal string library for C++ inspired by underscore.string
Stars: ✭ 7 (-85.42%)
Mutual labels:  library, string

tinystr crates.io Build Status Coverage Status

tinystr is a small ASCII-only bounded length string representation.

Usage

use tinystr::{TinyStr4, TinyStr8, TinyStr16, TinyStrAuto};

fn main() {
    let s1: TinyStr4 = "tEsT".parse()
        .expect("Failed to parse.");

    assert_eq!(s1, "tEsT");
    assert_eq!(s1.to_ascii_uppercase(), "TEST");
    assert_eq!(s1.to_ascii_lowercase(), "test");
    assert_eq!(s1.to_ascii_titlecase(), "Test");
    assert_eq!(s1.is_ascii_alphanumeric(), true);

    let s2: TinyStr8 = "New York".parse()
        .expect("Failed to parse.");

    assert_eq!(s2, "New York");
    assert_eq!(s2.to_ascii_uppercase(), "NEW YORK");
    assert_eq!(s2.to_ascii_lowercase(), "new york");
    assert_eq!(s2.to_ascii_titlecase(), "New york");
    assert_eq!(s2.is_ascii_alphanumeric(), false);

    let s3: TinyStr16 = "metaMoRphosis123".parse()
        .expect("Failed to parse.");

    assert_eq!(s3, "metaMoRphosis123");
    assert_eq!(s3.to_ascii_uppercase(), "METAMORPHOSIS123");
    assert_eq!(s3.to_ascii_lowercase(), "metamorphosis123");
    assert_eq!(s3.to_ascii_titlecase(), "Metamorphosis123");
    assert_eq!(s3.is_ascii_alphanumeric(), true);

    let s4: TinyStrAuto = "shortNoAlloc".parse().unwrap();
    assert!(matches!(s4, TinyStrAuto::Tiny { .. }));
    assert_eq!(s4, "shortNoAlloc");

    let s5: TinyStrAuto = "longFallbackToHeap".parse().unwrap();
    assert!(matches!(s4, TinyStrAuto::Heap { .. }));
    assert_eq!(s4, "shortNoAlloc");
}

Details

The crate provides three structs and an enum:

  • TinyStr4 an ASCII-only string limited to 4 characters.
  • TinyStr8 an ASCII-only string limited to 8 characters.
  • TinyStr16 an ASCII-only string limited to 16 characters.
  • TinyStrAuto (enum):
    • Tiny when the string is 16 characters or less.
    • Heap when the string is 17 or more characters.

The structs stores the characters as u32/u64/u128 and uses bitmasking to provide basic string manipulation operations:

  • is_ascii_numeric
  • is_ascii_alphabetic
  • is_ascii_alphanumeric
  • to_ascii_lowercase
  • to_ascii_uppercase
  • to_ascii_titlecase
  • PartialEq

TinyStrAuto stores the string as a TinyStr16 when it is short enough, or else falls back to a standard String. You should use TinyStrAuto when you expect most strings to be 16 characters or smaller, but occasionally you receive one that exceeds that length. Unlike the structs, TinyStrAuto does not implement Copy.

This set is sufficient for certain classes of uses such as unic-langid libraries.

no_std

Disable the std feature of this crate to make it #[no_std]. Doing so disables TinyStrAuto. You can re-enable TinyStrAuto in #[no_std] mode by enabling the alloc feature.

Performance

For those uses, TinyStr provides performance characteristics much better than the regular String.

Status

The crate is fully functional and ready to be used in production. The capabilities can be extended.

License

Licensed under either of Apache License, Version 2.0 or MIT license at your option.
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].