Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revision | |||
programming_languages:basic_data_structures [2019/10/19 23:51] – ↷ Page moved from basic_data_structures to programming_languages:basic_data_structures phreazer | programming_languages:basic_data_structures [2020/02/15 17:07] (current) – phreazer | ||
---|---|---|---|
Line 1: | Line 1: | ||
====== Basic data structures in different languages ====== | ====== Basic data structures in different languages ====== | ||
- | Having dealt with multiple different programming languages creates some confusion how and in which place the data structures are implemented in each of the languages. This page tries to provide some overview of basic ds. | + | Having dealt with multiple different programming languages creates some confusion how and in which place the data structures are implemented in each of the languages. This page tries to provide some overview of basic data structures. |
===== Concurrency ===== | ===== Concurrency ===== | ||
Line 65: | Line 64: | ||
size() | size() | ||
</ | </ | ||
+ | |||
+ | |||
==== Python 3 ==== | ==== Python 3 ==== | ||
+ | === collections.deque === | ||
< | < | ||
from collections import deque | from collections import deque | ||
Line 76: | Line 78: | ||
append, pop, popleft | append, pop, popleft | ||
</ | </ | ||
+ | |||
+ | === Queue === | ||
+ | |||
+ | * Multiproducer, | ||
+ | * Queue, SimpleQueue (no task tracking), LifoQueue, PriorityQueue | ||
+ | |||
+ | For uncomparable types: | ||
+ | |||
+ | < | ||
+ | from dataclasses import dataclass, field | ||
+ | from typing import Any | ||
+ | |||
+ | @dataclass(order=True) | ||
+ | class PrioritizedItem: | ||
+ | priority: int | ||
+ | item: Any=field(compare=False) | ||
+ | </ | ||
+ | |||
+ | === multiprocessing.Queue === | ||
+ | For multi-processing | ||
+ | |||
+ | ===== Heap ===== | ||
+ | Heap structure (binary tree with ordering); Priority queue | ||
+ | |||
+ | Use cases: | ||
+ | |||
+ | ==== Python ==== | ||
+ | |||
+ | Minheap implementation | ||
+ | |||
+ | < | ||
+ | import heapq | ||
+ | |||
+ | heapq.heappush, | ||
+ | heapq.heapify - Transform list to heap | ||
+ | </ | ||
+ | |||
+ | ===== Bisect ===== | ||
+ | Maintain list in sorted ordered on insertion. | ||
+ | |||
+ | ===== Array ===== | ||
+ | array module - " | ||
===== Math funcs ===== | ===== Math funcs ===== | ||