Vai al contenuto principale
ProdottiStrumenti desktopTASTECADVisualizzazione disegniTASTEFILESGestione fileTASTEFTPTrasferimento fileTASTESSHSpazio di lavoro remotoTASTEZIPCompressione ed estrazioneTASTEWINMGestione fileStrumenti per sviluppatoriTASTECODEAmbiente di sviluppo integrato per RustTASTESTUDIOAmbiente integrato di sviluppo e testTASTEETLIntegrazione dati (ETL)ServerTASTEREMOTEServer di desktop remotoTASTEGEOServer geospazialeTASTEMAILSpazio di lavoro emailInvestimentiTASTESTOCKApp desktop di trading automatico azionarioIniziaDownloadDocumentazioneAcquistaTutti i prodotti
Marketplace
Notizie
TecnologiaNotizieNotizie di sviluppo di oggiDocumentazioneLinguaggi di programmazioneRustTypeScriptJavaScriptPythonGoC#JavaCC++KotlinDartFramework frontend webNext.jsReactVue.js · NuxtSvelteKitAngularFramework serverSpring BootDjangoFastAPIASP.NET CoreNestJS · ExpressFramework per app e desktopTauriFlutterReact NativeElectronAlgoritmiBasi degli algoritmiAlgoritmi fondamentaliAlgoritmi avanzatiAlgoritmi pratici
CommunityProgettiLog di sviluppoPromptProblemi degli strumenti di IAVetrinaGuida alla community
CollaboraTrasferimento tecnicoRealizzazione del sito webRealizzazione di app desktopPipeline di rilascio e pagamentoPartner commercialeContatti
ServiziDesktop remotoPacchetti di installazione su misura
TASTEDEV
Prodotti

Strumenti desktop

TASTECADApri con leggerezza anche i disegni più complessiTASTEFILESSolo i file che servono, alla massima velocitàTASTEFTPLa via più ordinata per i tuoi fileTASTESSHUn legame più solido tra te e i tuoi serverTASTEZIPComprimi più veloce, estrai più sicuroTASTEWINMUn file manager a due pannelli pensato per la tastiera

Strumenti per sviluppatori

TASTECODEModifica, compila, esegui il debug e testa app Rust in un'unica finestraTASTESTUDIODalla modifica ai test remoti e alle correzioni IA approvateTASTEETLSposta i dati guardando i valori

Server

TASTEREMOTEUn desktop remoto che gira sul tuo serverTASTEGEOUn server geospaziale compatibile con GeoServer, ricostruito in RustTASTEMAILRiprendi il controllo della tua posta

Investimenti

TASTESTOCKTrading automatico azionario secondo le regole che decidi tu: quando e che cosa

Inizia

DownloadUltime versioni di ogni prodottoDocsCome usare ogni prodottoAcquistaAbbonamenti e licenze perpetueTutti i prodottiTutti i prodotti a colpo d’occhio
Tutti i prodotti
MarketplaceNotizie
Tecnologia

Notizie

Notizie di sviluppo di oggiAnnunci ufficiali su linguaggi, framework, GitHub e IADocumentazioneGuide a linguaggi, framework e algoritmi

Linguaggi di programmazione

RustTypeScriptJavaScriptPythonGoC#JavaCC++KotlinDart

Framework

Framework frontend webNext.jsReactVue.js · NuxtSvelteKitAngular
Framework serverSpring BootDjangoFastAPIASP.NET CoreNestJS · Express
Framework per app e desktopTauriFlutterReact NativeElectron

Algoritmi

Basi degli algoritmiAnalisi della complessità · Ordinamento · Ricerca · Strutture dati di base · Alberi e heapAlgoritmi fondamentaliVisita dei grafi · Cammini minimi e alberi ricoprenti · Programmazione dinamica · Algoritmi greedy · Divide et impera · BacktrackingAlgoritmi avanzatiAlgoritmi sulle stringhe · Matematica e teoria dei numeri · Manipolazione dei bit · Alberi di segmenti · Union-FindAlgoritmi praticiStrategia per colloqui di programmazione · Cache LRU · Rate limiting · Hashing consistente
Tutta la documentazione di sviluppo
Community
ProgettiScopri sviluppatori e lavoriLog di sviluppoDecisioni e lezioni appresePromptIstruzioni riutilizzabiliProblemi degli strumenti di IAProblemi e alternative di Claude, Codex, GeminiVetrinaRisultati completatiGuida alla communityCome sviluppiamo in modo aperto
Collabora
Trasferimento tecnicoApp native in Rust ed eguiRealizzazione del sito web10 lingue, account, documentazione e downloadRealizzazione di app desktopRust ed egui, senza WebViewPipeline di rilascio e pagamentoFirma, MSI, deb, rpm, AppImage, hashPartner commercialeConsigliaci e ricevi il 30%ContattiSviluppo, partnership e investimenti
Servizi
Desktop remotoRaggiungi il tuo computer dal browserPacchetti di installazione su misuraSolo il necessario, impostazioni precaricate
Acquista
IT
한국어EnglishDeutschEspañolFrançaisItalianoPortuguês (Brasil)日本語简体中文繁體中文
Accedi
Accedi
TASTEDEV

Dai piccoli strumenti a uno sviluppo migliore.

support@tastedev.netSostieni TASTEDEV
ProdottiGamma di prodottiAcquistaDocsDownloadMarketplaceAssistenza
CommunityProgettiLog di sviluppoPromptProblemi degli strumenti di IAVetrina
NormeChi siamoInformativa sulla privacyTermini di servizioCondizioni di abbonamentoRimborsiLinee guida della community
AccountAccediRegistrati
Visitatori
Oggi
Ieri
Visualizzazioni totali
Società
GXSOFT
Rappresentante
CHOI YOUNG GU
Numero di registrazione
853-44-00368
Indirizzo
9F V24, 351 Gyeongin-ro, Michuhol-gu, Incheon, Republic of Korea
Telefono
+82-10-4404-1523
E-mail
whitecalvin@tastedev.net
Responsabile privacy
CHOI YOUNG GU

© 2026 TASTEDEVLe informazioni sui prodotti si basano su fonti di sviluppo verificate.Rilasciato · in miglioramento

Documentazione di Manipolazione dei bit
Manipolazione dei bit
ConceptsHow It WorksImplementationComplexityPractice ProblemsReal-World Use
Discussioni

Guida a Manipolazione dei bit · 4/6

Complexity

Per ora questo capitolo è disponibile solo in inglese.

A single bitwise operation is one machine instruction, so on fixed-width integers it is O(1). What matters is how many times you repeat it and how many states a mask can describe. This chapter compares popcount strategies, measures subset and submask enumeration, and shows where bitmask DP stops being practical.

Basic operations

On w-bit integers, AND, OR, XOR, NOT, shifts, x & -x and x & (x - 1) all take O(1) time and space. Python integers are unbounded, so strictly an operation costs O(b) for a b-bit value, but anything that fits in 64 bits is effectively constant.

Popcount strategies

MethodTimeNotes
Check every bitO(w)simplest, always w rounds
Kernighan (x &= x - 1)O(k), k = set bitsfast for sparse values, worst case O(w)
8-bit lookup tableO(w / 8)needs a 256-entry table
SWAR parallel sumO(log w)branch-free shifts and adds
Hardware POPCNTO(1)used by int.bit_count, std::popcount, Integer.bitCount
def popcount_swar(x: int) -> int:
    # unsigned 32-bit values only
    x = x - ((x >> 1) & 0x55555555)
    x = (x & 0x33333333) + ((x >> 2) & 0x33333333)
    x = (x + (x >> 4)) & 0x0F0F0F0F
    return ((x * 0x01010101) & 0xFFFFFFFF) >> 24

assert all(popcount_swar(v) == v.bit_count() for v in (0, 1, 255, 2**32 - 1, 0xDEADBEEF))

If you need the popcount of every number from 0 to n, fill a table in O(n) with bits[i] = bits[i >> 1] + (i & 1).

Subset enumeration

With n items there are 2^n masks; testing n bits per mask costs O(2^n * n) time. Collecting every subset in a list also costs O(2^n * n) space, while a generator needs only O(n). Rough limits:

n2^n2^n * nFeel
101,024about 10 thousandinstant
1665,536about 1 millionfast
20
Domande su questo capitolo?
Capitolo precedenteImplementationCapitolo successivoPractice Problems
about 1.05 million
about 21 million
tens of ms in C++, seconds in Python
25about 33.5 millionabout 840 millionimpractical in Python
40about 1.1 trillion-needs meet in the middle

Submasks and 3^n

Looping over every mask and then over its submasks looks like O(4^n), but it is O(3^n): each item is either outside the mask, in the mask only, or in both mask and submask. For n = 15, 3^15 is about 14 million, which is fine.

n = 4
pairs = 0
for mask in range(1 << n):
    sub = mask
    while True:
        pairs += 1
        if sub == 0:
            break
        sub = (sub - 1) & mask
print(pairs, 3 ** n)   # 81 81

Subsets of a fixed size

If you only need subsets of size k, scanning all 2^n masks and filtering by popcount still costs O(2^n). When C(n, k) is much smaller than 2^n, generating combinations directly, as itertools.combinations does, costs O(C(n, k) * k). If you need them as masks, Gosper's hack finds the next mask with the same popcount in O(1).

def next_same_popcount(x: int) -> int:
    low = x & -x
    ripple = x + low
    return (((ripple ^ x) >> 2) // low) | ripple


mask, n = 0b0011, 4
while mask < (1 << n):
    print(format(mask, "04b"), end=" ")   # 0011 0101 0110 1001 1010 1100
    mask = next_same_popcount(mask)

Bitmask DP

With 2^n states and n transitions each, a bitmask DP runs in O(2^n * n). When the state is (set, last vertex), as in the traveling salesman problem (Held-Karp), it is O(2^n * n^2) time and O(2^n * n) space. TSP with n = 20 is about 400 million steps: fine in C++, hard in Python. Compared with trying all n! orders, n = 15 means 1.3 trillion versus about 7.4 million.

import math
for n in (10, 15, 20):
    print(n, math.factorial(n), (1 << n) * n * n)

Comparing set representations

RepresentationMembershipUnionMemoryBest for
Integer bitmaskO(1)O(1)w bitsup to 64 items
Bitset (std::bitset, BitSet)O(1)O(n / w)n bitsthousands to millions of items
Hash set (set)O(1) averageO(n)tens of bytes per itemwide, sparse domains
Sorted listO(log n)O(n)one slot per itemwhen order matters

Summary

Bitwise operations are O(1); the cost comes from repetitions and state counts. Subset enumeration is O(2^n * n), all mask/submask pairs are O(3^n), and bitmask DP is typically O(2^n * n) or O(2^n * n^2). These techniques shine when n is around 20 or less; beyond that, look for a different approach.

0 commenti

Commenti principaliPrima i più recenti

Accedi · Accedi per lasciare un commento.