Post
Topic
Board Announcements (Altcoins)
Re: [ANN][CLAM] CLAMs, Proof-Of-Chain, Proof-Of-Working-Stake, a.k.a. "Clamcoin"
by
dooglus
on 30/12/2015, 05:03:48 UTC
I did find a bit of a hackish way to check if a vector of unsigned chars is a "prefix" of a CKeyID:

How about this?

Code:
                bool isprefix=true;
                unsigned char* keyidarr = (unsigned char*) &keyid;
                for (unsigned int i = 0; i < vchID.size(); i++)
                  if (vchID[i] != keyidarr[i]) {
                    isprefix=false;
                    break;
                  }

The 'break' will stop the loop as soon as it finds a difference without needing to check isprefix each time through the loop.

You could get rid of isprefix all together, and just check whether i == vchID.size() after the loop is done. Iff that's true then it's a prefix:

Code:
                unsigned char* keyidarr = (unsigned char*) &keyid;
                unsigned int i;
                for (i = 0; i < vchID.size(); i++)
                  if (vchID[i] != keyidarr[i])
                    break;
                if (i == vchID.size()) // it's a prefix ...

Edit: I meant to say that I was meaning to help you out with this about 12 hours ago, but when I went to check on my testnet instance it was dead, and crashed every time I tried to restart it, so I spent today tracking down and fixing the bugs that caused that instead.