コード例 #1
0
bool FeatureIndex::buildBigramFeature(LearnerPath *path,
                                      const char *rfeature,
                                      const char *lfeature) {
  char rbuf[BUFSIZE];
  char lbuf[BUFSIZE];
  char *R[POSSIZE];
  char *L[POSSIZE];

  feature_.clear();
  std::strncpy(lbuf,  rfeature, BUFSIZE);
  std::strncpy(rbuf,  lfeature, BUFSIZE);

  size_t lsize = tokenizeCSV(lbuf, L, POSSIZE);
  size_t rsize = tokenizeCSV(rbuf, R, POSSIZE);

  for (std::vector<const char*>::const_iterator it = bigram_templs_.begin();
       it != bigram_templs_.end(); ++it) {
    const char *p = *it;
    os_.clear();

    for (; *p; p++) {
      switch (*p) {
        default: os_ << *p; break;
        case '\\': os_ << getEscapedChar(*++p); break;
        case '%': {
          switch (*++p) {
            case 'L': {
              const char *r = getIndex(const_cast<char **>(&p), L, lsize);
              if (!r) goto NEXT;
              os_ << r;
            } break;
            case 'R': {
              const char *r = getIndex(const_cast<char **>(&p), R, rsize);
              if (!r) goto NEXT;
              os_ << r;
            } break;
            case 'l':  os_ << lfeature; break;  // use lfeature as it is
            case 'r':  os_ << rfeature; break;
            default:
              CHECK_FALSE(false) << "unkonwn meta char: " <<  *p;
          }
        }
      }
    }

    os_ << '\0';

    ADDB(os_.str());

 NEXT: continue;
  }

  COPY_FEATURE(path->fvector);

  return true;
}
コード例 #2
0
ファイル: InstQuote.cpp プロジェクト: shigw/quote01
/* 写成二进制格式 */
int CInstQuoteDay::DumpToBytes(BYTE **pByte)
{
	int i;
	st_quoteitem *pLast;
	BYTE *p,*pBack;
	long lRec;
	long lBackWritePos;
	int iSize;
	
	pLast = nullptr;
	iSize = 0;
	
	
	/* 写文件头 */
	p = *pByte;
	iSize += DumpHeaderToBytes(&p, &lBackWritePos);
	
	ADDB(m_iQuoteArrayCount);
	for(i=0;i<m_iQuoteArrayCount;i++)
	{
		ADDB(m_pQuoteArray[i]);
	}
	
	lRec = 0;
	for(i=0;i<m_iQuoteArrayCount;i++)
	{
		if (m_pQuoteArray[i].m_pQuote == nullptr)
			continue;
		iSize += m_pQuoteArray[i].m_pQuote->DumpToBytes(&p);
		lRec++;
	}
	
	pBack = *pByte + lBackWritePos;
	memcpy(pBack,&m_iQuoteArrayCount,sizeof(long));
	pBack+=sizeof(long);
	memcpy(pBack,&lRec,sizeof(long));
	*pByte = p;
	return iSize;
}
コード例 #3
0
bool FeatureIndex::buildUnigramFeature(LearnerPath *path,
                                       const char *ufeature) {
  char ubuf[BUFSIZE];
  char *F[POSSIZE];

  feature_.clear();
  std::strncpy(ubuf, ufeature, BUFSIZE);
  size_t usize = tokenizeCSV(ubuf, F, POSSIZE);

  for (std::vector<const char*>::const_iterator it = unigram_templs_.begin();
       it != unigram_templs_.end(); ++it) {
    const char *p = *it;
    os_.clear();

    for (; *p; p++) {
      switch (*p) {
        default: os_ << *p; break;
        case '\\': os_ << getEscapedChar(*++p); break;
        case '%': {
          switch (*++p) {
            case 'F':  {
              const char *r = getIndex(const_cast<char **>(&p), F, usize);
              if (!r) goto NEXT;
              os_ << r;
            } break;
            case 't':  os_ << (size_t)path->rnode->char_type;     break;
            case 'u':  os_ << ufeature; break;
            default:
              CHECK_FALSE(false) << "unkonwn meta char: " <<  *p;
          }
        }
      }
    }

    os_ << '\0';
    ADDB(os_.str());

 NEXT: continue;
  }

  COPY_FEATURE(path->rnode->fvector);

  return true;
}
コード例 #4
0
ファイル: InstQuote.cpp プロジェクト: shigw/quote01
int CInstQuoteDay::DumpHeaderToBytes(BYTE **pByte, long *plBackWritePos)
{
	int i;
	char m_sTmp[20];
	long l;
	BYTE *p;
	int iSize;
	
	memset(m_sTmp,0,sizeof(m_sTmp));
	strcpy(m_sTmp,VERSION_STR);
	
	p = *pByte;
	iSize = 0;

#define ADDA(a,b)	memcpy(p,a,b);	\
	p+=b;			\
	iSize  += b;
#define ADDB(a)		memcpy(p,&a,sizeof(a));	\
	p+=sizeof(a);	\
	iSize += sizeof(a);
	
	ADDA(m_sTmp,20);
	ADDA(m_sExchangeID, 10);
	ADDA(m_sInstrumentID, 40);
	ADDA(m_sTradingDay, 10);
	ADDA(m_sInstrumentName, 40);
	
	ADDB(m_ctrl.m_wnSeconds);
	ADDB(m_ctrl.m_wmQuotes);
	ADDB(m_ctrl.m_iTimeSegmentCount);
	
	for(i=0;i<m_ctrl.m_iTimeSegmentCount;i++)
	{
		ADDB(m_ctrl.m_dwSegmentBeginTime[i]);
		ADDB(m_ctrl.m_dwSegmentEndTime[i]);
	}
	/* 然后是总记录数 / 实际记录数*/
	*plBackWritePos = (long)iSize;
	l = 0;
	ADDB(l);
	ADDB(l);
	*pByte = p;
	return iSize;
}
コード例 #5
0
static UINT32 opINCB(v60_state *cpustate) /* TRUSTED */
{
	UINT8 appb;
	cpustate->modadd = cpustate->PC + 1;
	cpustate->moddim = 0;

	cpustate->amlength1 = ReadAMAddress(cpustate);

	if (cpustate->amflag)
		appb = (UINT8)cpustate->reg[cpustate->amout];
	else
		appb = cpustate->program->read_byte(cpustate->amout);

	ADDB(appb, 1);

	if (cpustate->amflag)
		SETREG8(cpustate->reg[cpustate->amout], appb);
	else
		cpustate->program->write_byte(cpustate->amout, appb);

	return cpustate->amlength1 + 1;
}
コード例 #6
0
ファイル: op3.c プロジェクト: BirchJD/xmame-0.103-RPi
UINT32 opINCB(void) /* TRUSTED */
{
	UINT8 appb;
	modAdd=PC+1;
	modDim=0;

	amLength1=ReadAMAddress();

	if (amFlag)
		appb=(UINT8)v60.reg[amOut];
	else
		appb=MemRead8(amOut);

	ADDB(appb, 1);

	if (amFlag)
		SETREG8(v60.reg[amOut], appb);
	else
		MemWrite8(amOut, appb);

	return amLength1+1;
}
コード例 #7
0
ファイル: partial.c プロジェクト: JasonHeyward/c
int main ( void )
{
    int* x3 = malloc(3);
    float         f,   *f3   = malloc(3);
    int* x4 = malloc(4);
    double        d,   *d7   = malloc(7);
    int* x5 = malloc(5);
    long long int lli, *lli7 = malloc(7);
    int* x6 = malloc(6);
    char          c,   *c0   = malloc(0);
    int* x7 = malloc(7);
    short int     s,   *s1   = malloc(1);
    int  x;
    int* y4 = malloc(4);
    int* y5 = malloc(5);
    int* y6 = malloc(6);
    int* y7 = malloc(7);

#define ADDB(ptr, n)  ((int*)(((unsigned long)(ptr)) + (n)))

    // All these overrun by a single byte;  the reads are happening at
    // different alignments.
    x = * ADDB(x3,0);    // ok if --partial-loads-ok=yes
    x = * ADDB(x4,1);
    x = * ADDB(x5,2);
    x = * ADDB(x6,3);
    x = * ADDB(x7,4);    // ok if --partial-loads-ok=yes

    // These are fine
    x = * ADDB(y4,0);
    x = * ADDB(y5,1);
    x = * ADDB(y6,2);
    x = * ADDB(y7,3);

    // These are all bad, at different points along
    x = * ADDB(x3,-1);   // before
    x = * ADDB(x3, 0);   // inside      // ok if --partial-loads-ok=yes ...
    x = * ADDB(x3, 1);   // inside      // ... but only on 32 bit platforms
    x = * ADDB(x3, 2);   // inside      // ... ditto
    x = * ADDB(x3, 3);   // after

    // These are all bad
    f   = * f3;    // ok if --partial-loads-ok=yes  // ... ditto
    d   = * d7;
    lli = * lli7;  // ok if --partial-loads-ok=yes  see XXX below
    c   = * c0;
    s   = * s1;

    return 0;
}