Skip to content

Instantly share code, notes, and snippets.

@hailangx
Created January 3, 2015 15:00
Show Gist options
  • Select an option

  • Save hailangx/596833e6aa77e3e5a140 to your computer and use it in GitHub Desktop.

Select an option

Save hailangx/596833e6aa77e3e5a140 to your computer and use it in GitHub Desktop.

Revisions

  1. HaiyangXu created this gist Jan 3, 2015.
    17 changes: 17 additions & 0 deletions bitsmap.cpp
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,17 @@
    #define BITSPERWORD sizeof(int)*8
    #define SHIFT 5
    #define MASK 0x1f
    #define N 10000000
    int a[1+N/BITSPERWORD];

    void set(int i){
    a[i/BITSPERWORD]|=(1<<(i%BITSPERWORD));
    }

    void clr(int i){
    a[i/BITSPERWORD]&=~(1<<(i%BITSPERWORD));
    }

    int test(int i){
    return a[i/BITSPERWORD]&(1<<(i%BITSPERWORD));
    }