You can't convert list of lists to a map in Clojure
#clojure #programming #datastructures
You can't convert list of lists to a map in Clojure
#datastructures #Programming #clojure
Randomly thinking about #bikeshedding when #programming the size if a #filesize #integer in a #FileFormat, though I guess it could be used for any #DataStructures in #ComputerScience.
If you know how big the largest number you're going to have to keep track of is, you can cut down on the size of the integer by choosing a number of bits that's just big enough to fit that... But there are ways you can get really screwy with this.
For example, you could choose a number that isn't the standard 8, 16, 32, 64 by going above that and using the extra bits as flags or something, like making it 24-bit and using the last 8 bits as another byte. Or you could lower the granularity, and multiply the value of whatever the number is to get bigger numbers at the expense of numbers not divisible by that.
The issue with thinking of this however is that we are talking a handful of bytes in what could be megabytes, so less than 0.1% of the byte size...
(more)
#bikeshedding #programming #filesize #integer #fileformat #datastructures #computerscience
Started reading the #clrs book. My first formal introduction to #algorithms and #datastructures!
#clrs #algorithms #datastructures
In today's #datastructures illustrated, we have FIFO queue with block allocated storage
I just published "PDF: purely functional data structures in #Elm" on GitHub.
These are Elm reimplementations of the data structures presented in the book "#Purely #Functional #DataStructures" (1999) by Prof. Okasaki. It is the only one of its kid that I am aware. It is a tour de force of functional thinking. The book includes #StandardML and #Haskell implementations.
Okasaki is a descendant of the ML tradition. His PhD advisor at CMU during the mid 1990s was Prof. Harper who wrote "Programming in Standard ML" (2011), contributed to the definition of the language, and was a member of the ML posse, alongside Milner, Tofte, Reppy, MacQueen, et al.
I chose #Elm for the following reasons:
β’ Elm is a purely functional language
β’ Elm does not yet have a comprehensive library of data structures
β’ Elm evolves at a deliberate pace, with subsuming to the modern CI/CD pipeline pressure
β’ Elm is one of the simplest #FP languages
β’ Elm is sane
β’ These properties make Elm a good candidate for use in #CS education, for teaching FP, for teaching data structures, and for teaching disciplined web programming, and a comprehensive collection of data structures could be of use in undergraduate education
An unstated, but no less important, reason for my choosing Elm is Python fatigue. I currently use Python at work, and I am also expanding my "CLRS algorithms in Jupyter notebooks" project. I like Python, but many hours of Python a day is deleterious to my #MentalHealth. Elm is both the prophylactic and the cure.
Please note that both PDF and CLRS are my solo projects, and they are works in progress that grow incrementally. Both projects aim to help #CS undergraduate students.
#mentalhealth #cs #fp #haskell #standardml #datastructures #functional #purely #elm
I used it when I was busy with my #datastructures course. All of the #JetBrains software has advanced debugging tools.
So I used #PyCharm for #Python, #CLion for C++ and #InteliJ for #Java. It allowed me to debug connections and relationships in data structures.
Today, I wouldn't personally use it because I know those stuff now, and I have my own workflow now. I never step through code anymore, I don't even use the debugging in #VScode anymore.
When required, I am a degenerate "console.log" debugger.
#datastructures #jetbrains #pycharm #python #clion #intelij #java #vscode
E-graphs from A to almost Z. Very well-written and easy to understand.
* may use a similar approach in my own writing. Thanks @ Cole-K. π #datastructures #datastructure https://www.cole-k.com/2023/07/24/e-graphs-primer/#fnref:6
#datastructures #datastructure
4-min interview w/ Tarjan on his inverse-Ackermann upper bound for the union-find data structure . Turns out he got a matching lower bound on that algorithm first - I didn't know about the lower bound before! Interesting story behind the path of research.
#complexity #algorithms #datastructures
(8/8) #Optimizing nested #datastructures in #Python:
**Profiling:** Before optimizing, profile your code to identify resource-intensive areas and focus on the most impactful improvements.
Example: Use Python's `cProfile` module to analyze code performance.
#optimizing #datastructures #python
(7/8) #Optimizing nested #datastructures in #Python:
**Generators or lazy evaluation:** Use generators or lazy evaluation techniques to process data incrementally, saving memory and improving performance.
Example: Use a generator to read large files line-by-line.
#optimizing #datastructures #python
(6/8) #Optimizing nested #datastructures in #Python:
**Data compression:** Reduce memory usage by compressing data with repetitive patterns using gzip or zlib.
Example: Compress large text data with gzip.
#optimizing #datastructures #python
(5/8) #Optimizing nested #datastructures in #Python:
**Appropriate data structures:** Choose data structures based on access patterns. Use dictionaries when accessing elements by specific keys.
Example: Use a dictionary to store items with unique identifiers.
#optimizing #datastructures #python
(4/8) #Optimizing nested #datastructures in #Python:
**Dictionaries with fixed keys:** If inner dictionaries have constant keys, consider using named tuples or custom classes for better performance.
Example: Replace `{'x': 1, 'y': 2}` with a named tuple or class `Point(x=1, y=2)`.
#optimizing #datastructures #python
(3/8) #Optimizing nested #datastructures in #Python:
**Use NumPy or Pandas:** For numerical computations or tabular data, utilize NumPy arrays or Pandas DataFrames for faster operations.
Example: Convert a nested list into a NumPy array for mathematical operations.
#optimizing #datastructures #python
(2/8) #Optimizing nested #datastructures in #Python:
**Custom classes:** Create specific classes for inner dictionaries with fixed keys to improve efficiency, readability, and maintainability.
Example: Instead of `{'name': 'John', 'age': 30}`, use a `Person` class with attributes `name` and `age`.
#optimizing #datastructures #python
(1/8) #Optimizing nested #datastructures in #Python:
**Reduce nesting:** Avoid unnecessary layers of nesting. Flatten the structure or use simpler data types like tuples when inner dictionaries have few keys.
Example: Instead of `List[Dict[Any, List[Dict[Any, Any]]]]`, consider `List[Tuple[Key, Value]]`.
#optimizing #datastructures #python
The last few weekends I've been working on my own rust implementation of a forest-of-B+-trees data structure, which is very useful for representing dynamic graphs, very similar to cranelift_bforest (https://docs.rs/cranelift-bforest/latest/cranelift_bforest/)
My main motivation is that I want to a) have a larger branching factor to reduce the number of random accesses during iteration b) have size optimizations for small trees that don't even fill half a single node and c) keep track of the size for every subtree, so every tree can efficiently be used as an order-statistic tree as well as for optimizing multi-tree operations like intersection or more general joins.
This weekend I've got single item insert and remove fully implemented and did some fuzzing which did find the one place during rebalancing where I forgot to update the subtree size.
I also did some limited initial benchmarking, and after a bit of profiling and adding inline annotations the performance looks promising. Quite a bit faster than Vec<BTreeSet<T>> and never slower than cranelift_bforest, sometimes even a bit faster. The same is true for memory usage.
These benchmarks are far from being representative of all my use cases, but they do give me confidence that this isn't going to be a complete waste of time :)
Before publishing a first version I still have to come up with a name for the crate though and I want to implement a bit more of the basic functionality you'd expect to have, like iteration :D
#datastructures #rustlang #rust
Today on Medium, an excerpt from the new Python version of A Common Sense Guide to Data Structures and Algorithms by Jay Wengrow:
https://medium.com/pragmatic-programmers/big-o-in-everyday-code-73a2b18b3292
If you like the excerpt and want the book, head over to DevTalk to find a 35% off promo code:
https://devtalk.com/books/a-common-sense-guide-to-data-structures-and-algorithms-in-python-volume-1
#datastructures #algorithms #python #pragprog #books
#datastructures #algorithms #python #pragprog #books
Flattened abstract syntax trees.
#ast #compilers #datastructures #rustlang #programming