flowchart TD
A[Represent set as integer mask] --> B[Use bit ops set clear check toggle]
B --> C[Enumerate masks 0 1 n 1]
C --> D[Inspect each bit position]
D --> E{bit is on}
E -- Yes --> F[Include element]
E -- No --> G[Skip element]
F --> H{more bits}
G --> H
H -- Yes --> D
H -- No --> I[Emit subset state]
sequenceDiagram
participant M as mask
participant B as bit i
participant S as subset
loop for each mask
M->>B: test bit
alt on
B->>S: include element
end
end
# [Bit Masking 템플릿: 아키텍트 버전]# Use Case: 집합 상태 관리, 부분 집합# Components: Bitmask (정수), Bit Operations# Constraint: 최대 32~64개 원소defbit_operations():# 1. 기본 비트 연산 (Basic Operations)# i번째 비트 확인 (Check)defcheck_bit(mask,i):return(mask&(1<<i))!=0# i번째 비트 설정 (Set)defset_bit(mask,i):returnmask|(1<<i)# i번째 비트 해제 (Clear)defclear_bit(mask,i):returnmask&~(1<<i)# i번째 비트 토글 (Toggle)deftoggle_bit(mask,i):returnmask^(1<<i)# 켜진 비트 개수 (Count)defcount_bits(mask):count=0whilemask:count+=mask&1mask>>=1returncountreturncheck_bit,set_bit,clear_bit,toggle_bit,count_bits