Monthly Archives: October 2010

A simple read/write spin lock

  class RWSpinLock {   public:     RWSpinLock();     void readLock();     void readUnlock();     void writeLock();     void writeUnlock();   private:     const static uint32_t WRITING = 0x80000000u;     volatile uint32_t state;     RWSpinLock(const RWSpinLock&);     RWSpinLock& operator= (const … Continue reading

Posted in Programming | Leave a comment

Simple linear palindrom finding algorithm

A simple algorithm designed by Manacher in 1975. It scans the longest palindrom in left-to-right fashion. int palindrom_odd(const char *st, int n, int *p) {   int a = 0, m = 1;   p[0] = 1;   for (int i … Continue reading

Posted in Programming | Leave a comment