Luciano Ramalho - Set Practice: learning from Python's set types - PyCon 2019

"Speaker: Luciano Ramalho
Key takeaways:
1. Set operations enable simpler and faster solutions for many tasks;
1. Python's set classes are lessons in elegant, idiomatic API design;
1. A set class is a suitable context for implementing operator overloading.
Boolean logic and set theory are closely related. In practice, we will see cases where set operations provide simple and fast declarative solutions to programming problems that otherwise require complicated and slow procedural coding.
Python's set built-ins and ABCs provide a rich and well designed API. We will consider their interfaces, and how they can inspire the creation of Pythonic APIs for your own classes.
Finally, we will discuss operator overloading - a technique that is not suitable everywhere, but certainly makes sense with sets. Taking a few operators as examples, we will study their implementation in a new `UintSet` class for integer elements. `UintSet` fully implements the `MutableSet` interface over a totally different internal representation based on a bit array instead of a hash table. Membership tests run in O(1) time like the built-in sets (however, `UintSet` is currently pure Python, so YMMV). Using bit arrays allow core set operations like intersection and union to be implemented with fast bitwise operators, and provides compact storage for dense sets of integers.
Slides can be found at: speakerdeck.com/pycon2019 and github.com/PyCon/2019-slides"

Пікірлер: 6

  • @LucianoRamalho
    @LucianoRamalho5 жыл бұрын

    Slides are here: speakerdeck.com/ramalho/python-set-practice-at-pycon

  • @CristianCiupitu
    @CristianCiupitu4 жыл бұрын

    Since this is based on a bit array, I'd like to point out the "Bit Twiddling Hacks" page [1]. It's for the C programming language, but some techniques might also work for Python. I tried Kernighan's bit counting method [2] and it was a tiny bit faster than Luciano's naive `count_ones` function [3]; at least that's what I got on Python 3.7. [1]: graphics.stanford.edu/~seander/bithacks.html [2]: graphics.stanford.edu/~seander/bithacks.html#CountBitsSetKernighan [3]: github.com/standupdev/uintset/blob/e05b9352c15fede230a841c0e6616dc7ce7e73a3/bitops.py#L4

  • 5 жыл бұрын

    Slides are at neither link in the description

  • @jonasherseth5306

    @jonasherseth5306

    5 жыл бұрын

    You can find them on his github though: github.com/standupdev/set-practice

  • @LucianoRamalho

    @LucianoRamalho

    5 жыл бұрын

    Thanks for reporting that. Slides URL: speakerdeck.com/ramalho/python-set-practice-at-pycon

  • @LucianoRamalho

    @LucianoRamalho

    5 жыл бұрын

    You may also be interested in the source code of my UintSet class: github.com/standupdev/uintset