/** * Python collections module for TypeScript * * Provides specialized container datatypes including Counter for counting * hashable objects, defaultdict for dictionaries with default values, and * deque for double-ended queues. * * @see {@link https://docs.python.org/3/library/collections.html | Python collections documentation} * @module */ /** * Counter: a dict subclass for counting hashable objects * * Elements are stored as keys and their counts are stored as values. */ declare class Counter extends Map { constructor(iterable?: Iterable); /** * Increment the count for a key */ increment(key: T, n?: number): void; /** * Get the count for a key (returns 0 for missing keys) */ get(key: T): number; /** * List the n most common elements and their counts * If n is undefined, list all elements from most common to least * Uses ES2023 Array.prototype.toSorted() for immutable sorting */ mostCommon(n?: number): [T, number][]; /** * Iterate over elements, repeating each as many times as its count */ elements(): Generator; /** * Subtract counts from another iterable or Counter */ subtract(iterable: Iterable | Counter): void; /** * Add counts from another iterable or Counter */ update(iterable: Iterable | Counter): void; /** * Return total count of all elements */ total(): number; } /** * defaultdict: a dict that provides default values for missing keys * * Uses a Proxy to automatically call the factory function for missing keys. */ declare function defaultdict(factory: () => V): Map & { get(key: K): V; }; /** * deque: double-ended queue with O(1) append and pop from both ends */ declare class deque { private items; private maxlen; constructor(iterable?: Iterable, maxlen?: number); /** * Add element to the right end */ append(x: T): void; /** * Add element to the left end */ appendLeft(x: T): void; /** * Remove and return element from the right end */ pop(): T | undefined; /** * Remove and return element from the left end */ popLeft(): T | undefined; /** * Extend the right side with elements from iterable */ extend(iterable: Iterable): void; /** * Extend the left side with elements from iterable */ extendLeft(iterable: Iterable): void; /** * Rotate the deque n steps to the right (negative n rotates left) */ rotate(n?: number): void; /** * Remove all elements */ clear(): void; /** * Number of elements */ get length(): number; /** * Make iterable */ [Symbol.iterator](): Generator; /** * Convert to array */ toArray(): T[]; } type collectionsModule_Counter = Counter; declare const collectionsModule_Counter: typeof Counter; declare const collectionsModule_defaultdict: typeof defaultdict; type collectionsModule_deque = deque; declare const collectionsModule_deque: typeof deque; declare namespace collectionsModule { export { collectionsModule_Counter as Counter, collectionsModule_defaultdict as defaultdict, collectionsModule_deque as deque }; } export { Counter as C, deque as a, collectionsModule as c, defaultdict as d };