patricia_tree | A memory-efficient patricia tree implementation | Dataset library

 by   sile Rust Version: 0.6.0 License: MIT

kandi X-RAY | patricia_tree Summary

kandi X-RAY | patricia_tree Summary

patricia_tree is a Rust library typically used in Artificial Intelligence, Dataset applications. patricia_tree has no bugs, it has no vulnerabilities, it has a Permissive License and it has low support. You can download it from GitHub.

[License: MIT] Memory-efficient data structures based on patricia tree (a.k.a, radix tree). A common prefixes of the keys in a patricia tree are represented by a shared path. So if the prefixes of the key set is highly redundant, the memory usage of the resulting patricia tree will be drastically less than more generic data structures (e.g., BTreeMap). See [Radix tree] for more details.
Support
    Quality
      Security
        License
          Reuse

            kandi-support Support

              patricia_tree has a low active ecosystem.
              It has 80 star(s) with 14 fork(s). There are 7 watchers for this library.
              OutlinedDot
              It had no major release in the last 12 months.
              There are 0 open issues and 10 have been closed. On average issues are closed in 102 days. There are no pull requests.
              It has a neutral sentiment in the developer community.
              The latest version of patricia_tree is 0.6.0

            kandi-Quality Quality

              patricia_tree has no bugs reported.

            kandi-Security Security

              patricia_tree has no vulnerabilities reported, and its dependent libraries have no vulnerabilities reported.

            kandi-License License

              patricia_tree is licensed under the MIT License. This license is Permissive.
              Permissive licenses have the least restrictions, and you can use them in most projects.

            kandi-Reuse Reuse

              patricia_tree releases are available to install and integrate.
              Installation instructions are not available. Examples and code snippets are available.

            Top functions reviewed by kandi - BETA

            kandi's functional review helps you automatically verify the functionalities of the libraries and avoid rework.
            Currently covering the most popular Java, JavaScript and Python libraries. See a Sample of patricia_tree
            Get all kandi verified functions for this library.

            patricia_tree Key Features

            No Key Features are available at this moment for patricia_tree.

            patricia_tree Examples and Code Snippets

            No Code Snippets are available at this moment for patricia_tree.

            Community Discussions

            QUESTION

            Rust - Why such a big difference in memory usage between malloc/alloc and more 'idiomatic' approaches
            Asked 2020-Jul-04 at 21:44

            I've been using and modifying this library https://github.com/sile/patricia_tree

            One thing that bothered a bit was how much unsafe was used in node.rs, particularly, it's defined as just a pointer to some heap location. When doing the first benchmark listed on the readme page (wikipedia inputs), the PatriciaSet uses ~700mb (PatriciaSet is just holding a Node at it's root)

            ...

            ANSWER

            Answered 2020-Jul-04 at 20:05

            You're seeing increased memory use for a couple of reasons. I'll assume a standard 64-bit Unix system.

            First, a pointer is 8 bytes. An Option<*mut Node> is 16 bytes because pointers aren't subject to the nullable optimization that happens with references. References can never be null, so the compiler can convert an Option<&'a V> into a null pointer if the value is None and a regular pointer if it's Some, but pointers can be null so that can't happen here. Rust makes the size of the enum field the same size as the size of the data type, so you use 16 bytes per pointer here.

            The easiest and most type-safe way to deal with this is just to use Option>>. Doing that drops your structure by 16 bytes total.

            Second, your SmallVec is 32 bytes in size. They avoid needing a heap allocation in some cases, but they aren't, despite the name, necessarily small. You can use a regular Vec or a boxed slice, which will likely result in lower memory usage at the cost of an additional allocation.

            With those changes and using a Vec, your structure will be 48 bytes in size. With a boxed slice, it will be 40. The original used 72. How much savings you see will depend on how big your labels are, since you'll need to allocate space for them.

            The required alignment for this structure is 8 bytes because the largest alignment of any type (the pointer) is 8 bytes. Even on architectures like x86-64 where alignment is not required for all types, it is still faster, and sometimes significantly so, so the compiler always does it.

            The original code was not properly aligned at all and will either outright fail (on SPARC), perform badly (on PowerPC), or require an alignment trap into the kernel if they're enabled (on MIPS) or fail if they're not. An alignment trap into the kernel for unaligned access performs terribly because you have to do a full context switch just to load and shift two words, so most people turn them off.

            The reason that this is not properly aligned is because Node contains a pointer and it appears in the structure at an offset which is not guaranteed to be a multiple of 8. If it were rewritten such that the child and sibling attributes came first, then it would be properly aligned provided the memory were suitably aligned (which malloc guarantees but your Rust allocation does not). You could create a suitable Layout with Layout::from_size_align(block_size, std::mem::align_of::<*mut Node>()).

            So while the original code worked on x86-64 and saved a bunch of memory, it performed badly and was not portable.

            The code I used for this example is simply the following, plus some knowledge about how Rust does nullable types and knowledge about C and memory allocation:

            Source https://stackoverflow.com/questions/62725054

            Community Discussions, Code Snippets contain sources that include Stack Exchange Network

            Vulnerabilities

            No vulnerabilities reported

            Install patricia_tree

            You can download it from GitHub.
            Rust is installed and managed by the rustup tool. Rust has a 6-week rapid release process and supports a great number of platforms, so there are many builds of Rust available at any time. Please refer rust-lang.org for more information.

            Support

            For any new features, suggestions and bugs create an issue on GitHub. If you have any questions check and ask questions on community page Stack Overflow .
            Find more information at:

            Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items

            Find more libraries
            CLONE
          • HTTPS

            https://github.com/sile/patricia_tree.git

          • CLI

            gh repo clone sile/patricia_tree

          • sshUrl

            git@github.com:sile/patricia_tree.git

          • Stay Updated

            Subscribe to our newsletter for trending solutions and developer bootcamps

            Agree to Sign up and Terms & Conditions

            Share this Page

            share link