bool HashTableT<Key_t, Val_t>::set ( long initialNumTerms, char *buf, long bufSize, bool allowDupKeys) { reset(); m_allowDupKeys = allowDupKeys; // return setTableSize ( initialNumTerms ); // . set table size with buffer and bufferSize return setTableSize ( initialNumTerms, buf, bufSize ); }
// returns false and sets errno on error bool HashTableX::set ( long ks , long ds , long initialNumTerms , char *buf , long bufSize , bool allowDups , long niceness , char *allocName ) { reset(); m_ks = ks; m_ds = ds; m_allowDups = allowDups; m_niceness = niceness; m_needsSave = true; m_isSaving = false; m_maxSlots = 0x7fffffffffffffffLL; // sanity check. assume min keysize of 4 because we do *(long *)key // logic below!! if ( ks < 4 ) { char *xx=NULL;*xx=0; } if ( ds < 0 ) { char *xx=NULL;*xx=0; } // auto? if ( initialNumTerms == -1 ) { long slotSize = ks + ds + 1; initialNumTerms = bufSize / slotSize; initialNumTerms /= 2; // fix it to not exceed bufSize } // set this m_allocName = allocName; return setTableSize ( initialNumTerms , buf , bufSize ); }
// both return false and set g_errno on error, true otherwise bool HashTableX::load ( char *dir, char *filename, char **tbuf, long *tsize ) { reset(); File f; f.set ( dir , filename ); if ( ! f.doesExist() ) return false; char *pdir = dir; if ( ! pdir ) pdir = ""; log(LOG_INFO,"admin: Loading hashtablex from %s%s",pdir,filename); if ( ! f.open ( O_RDONLY) ) return false; long numSlots; long numSlotsUsed; long off = 0; if ( ! f.read ( &numSlots , 4 , off ) ) return false; off += 4; if ( ! f.read ( &numSlotsUsed , 4 , off ) ) return false; off += 4; if ( ! f.read ( &m_ks , 4 , off ) ) return false; off += 4; if ( ! f.read ( &m_ds , 4 , off ) ) return false; off += 4; if ( ! setTableSize ( numSlots , NULL , 0 ) ) return false; if ( ! f.read ( m_keys , numSlots * m_ks , off ) ) return false; off += numSlots * m_ks; if ( m_ds && ! f.read ( m_vals , numSlots * m_ds , off ) ) return false; off += numSlots * m_ds; // whether the slot is empty or not if ( ! f.read ( m_flags , numSlots , off ) ) return false; off += numSlots ; m_numSlotsUsed = numSlotsUsed; // done if no text buf if ( ! tbuf ) { f.close(); return true; } // read in the tbuf size, next 4 bytes if ( ! f.read ( tsize , 4 , off ) ) return false; off += 4; // make a name for it char ttt[64]; sprintf(ttt,"%s-httxt",m_allocName); // alloc mem for reading in the contents of the text buf *tbuf = (char *)mmalloc ( *tsize , ttt );//"HTtxtbufx" ); if ( ! *tbuf ) return false; // read in the contents of the text buf if ( ! f.read ( *tbuf , *tsize , off ) ) return false; off += *tsize; // we should free it in reset() m_txtBuf = *tbuf; m_txtBufSize = *tsize; // close the file, we are done f.close(); m_needsSave = false; long totalMem = *tsize+m_numSlots*(m_ks+m_ds); log(LOG_INFO,"admin: Loaded hashtablex from %s%s %li total mem", pdir,filename, totalMem); return true; }
void FXTabSim::reiniciar(void) { FXint i; limpiar(); clearItems(); setTableSize(10,9); for ( i = 0; i < 9; i++ ) setColumnText(i, cabecera[i]); tope = -1; numRegs = 0; bloques->clear(); }
bool HashTableT<Key_t, Val_t>::addKey (Key_t key , Val_t value , long *slot) { // check to see if we should grow the table if ( 100 * (m_numSlotsUsed+1) >= m_numSlots * 75 ) { long growTo = ((long long) m_numSlots * 120LL ) / 100LL +128LL; if ( ! setTableSize ( growTo, NULL, 0 ) ) return false; } long long n; /* switch(sizeof(Key_t)) { case 8: n = ((unsigned long long)key) % ((unsigned long)m_numSlots); break; default: n = ((unsigned long)key) % ((unsigned long)m_numSlots); break; } */ if ( sizeof(Key_t) == 8 ) n = ((unsigned long long)key) % ((unsigned long)m_numSlots); else n = ((unsigned long)key) % ((unsigned long)m_numSlots); long count; for ( count = 0 ; count < m_numSlots ; count++ ) { if ( m_keys [ n ] == (Key_t)0 ) break; // if we allow dups, skip as if he is full... if ( m_keys [ n ] == key && ! m_allowDupKeys ) break; if ( ++n == m_numSlots ) n = 0; } // bail if not found if ( count >= m_numSlots ) { g_errno = ENOMEM; return log("hashtable: Could not add key. Table is full."); } if ( m_keys [ n ] == (Key_t)0 ) { // inc count if we're the first m_numSlotsUsed++; // and store the ky m_keys [ n ] = key; } // insert the value for this key m_vals [ n ] = value; if ( slot ) *slot = n; return true; }
FXTabSim::FXTabSim(FXComposite *p, FXObject *tgt, FXSelector sel, FXuint opts, FXint x , FXint y, FXint w, FXint h, FXint pl, FXint pr, FXint pt, FXint pb) : FXTable(p, tgt , sel, opts, x, y, w, h, pl, pr, pt, pb) { FXint i; FXint *clave; setTableSize(10,9); for ( i = 0; i < 9; i++ ) setColumnText(i, cabecera[i]); tope = -1; numRegs = 0; bloque = -1; bloques = new FXArray<FXint>; colores.size(14); }
// returns false and sets errno on error bool HashTableX::set ( long ks , long ds , long initialNumTerms , char *buf , long bufSize , bool allowDups , long niceness , char *allocName , // in general you want keymagic to ensure your // keys are "random" for good hashing. it doesn't // really slow things down either. bool useKeyMagic ) { reset(); m_ks = ks; m_ds = ds; m_allowDups = allowDups; m_niceness = niceness; m_needsSave = true; m_isSaving = false; m_maxSlots = 0x7fffffffffffffffLL; // fi it so when you first call addKey() it does not grow your table! if ( initialNumTerms < 32 ) initialNumTerms = 32; // sanity check. assume min keysize of 4 because we do *(long *)key // logic below!! if ( ks < 4 ) { char *xx=NULL;*xx=0; } if ( ds < 0 ) { char *xx=NULL;*xx=0; } // auto? if ( initialNumTerms == -1 ) { long slotSize = ks + ds + 1; initialNumTerms = bufSize / slotSize; initialNumTerms /= 2; // fix it to not exceed bufSize } // set this m_allocName = allocName; m_useKeyMagic = useKeyMagic; return setTableSize ( initialNumTerms , buf , bufSize ); }
bool HashTableT<Key_t, Val_t>::load ( char* filename , char **tbuf , long *tsize ) { reset(); File f; f.set ( filename ); if ( ! f.doesExist() ) return true; log(LOG_INFO,"admin: Loading hashtable from %s",filename); if ( ! f.open ( O_RDONLY) ) return false; long numSlots; long numSlotsUsed; long off = 0; if ( ! f.read ( &numSlots , 4 , off ) ) return false; off += 4; if ( ! f.read ( &numSlotsUsed , 4 , off ) ) return false; off += 4; if ( ! setTableSize ( numSlots , NULL , 0 ) ) return false; long ks = sizeof(Key_t); long vs = sizeof(Val_t); // corruption check if ( f.getFileSize() < ks * numSlots + vs * numSlots - 8 ) return false; if ( ! f.read ( m_keys , numSlots * ks , off ) ) return false; off += numSlots * ks; if ( ! f.read ( m_vals , numSlots * vs , off ) ) return false; off += numSlots * vs; m_numSlotsUsed = numSlotsUsed; // done if no text buf if ( ! tbuf ) { f.close(); return true; } // read in the tbuf size, next 4 bytes if ( ! f.read ( tsize , 4 , off ) ) return false; off += 4; // alloc mem for reading in the contents of the text buf *tbuf = (char *)mmalloc ( *tsize , "HTtxtbuf" ); if ( ! *tbuf ) return false; // read in the contents of the text buf if ( ! f.read ( *tbuf , *tsize , off ) ) return false; off += *tsize; // close the file, we are done f.close(); return true; }
long HashTableT<Key_t, Val_t>::deserialize(char* s) { char *p = s; long numSlots = *(long*)p; p += sizeof(long); long numSlotsUsed = *(long*)p; p += sizeof(long); setTableSize(numSlots, m_buf, m_bufSize ); if(m_numSlots != numSlots) { return -1; } if(m_numSlots == 0) { m_numSlotsUsed = numSlotsUsed; return p - s; } memcpy((char*)m_keys, p, sizeof(Key_t) * numSlots); p += sizeof(Key_t) * numSlots; memcpy((char*)m_vals, p, sizeof(Val_t) * numSlots); p += sizeof(Val_t) * numSlots; m_numSlotsUsed = numSlotsUsed; return p - s; }
// . returns false and sets g_errno on error, returns true otherwise // . adds scores if termId already exists in table bool HashTableX::addKey ( void *key , void *val , long *slot ) { // if saving, try again later if ( m_isSaving || ! m_isWritable ) { g_errno = ETRYAGAIN; return false; } // check to see if we should grow the table. now we grow // when 25% full to make operations faster so getLongestString() // doesn't return such big numbers! if ( (m_numSlots < 20 || 2 * m_numSlotsUsed >= m_numSlots) && m_numSlots < m_maxSlots ) { long long growTo = ((long long)m_numSlots * 150LL )/100LL+20LL; if ( growTo > m_maxSlots ) growTo = m_maxSlots; if ( ! setTableSize ( (long)growTo , NULL , 0 ) ) return false; } long n = (*(unsigned long *)(((char *)key)+m_maskKeyOffset)) & m_mask; long count = 0; m_needsSave = true; while ( count++ < m_numSlots ) { // this is set to 0x00 if empty if ( m_flags [ n ] == 0 ) break; // breathe //QUICKPOLL(m_niceness); // use "n" if key matches if ( *(long *)(m_keys + m_ks * n) == *(long *)key && // if we are a 4 byte key no need to do the memcmp (m_ks==4||memcmp (m_keys + m_ks * n, key, m_ks )==0) ) { // if allow dups is true it must also match the data if ( ! m_allowDups ) break; // . this behaviour is expected by Events.cpp calling // g_places.addKey(h,&pd) // . TODO: think about adding m_allowRepeatedData // and only doing this memcmp() if that is false // . NO! computeSimilarity adds the same termid with // same score quite often //if ( memcmp(m_vals+n*m_ds,val,m_ds) == 0 ) // break; // otherwise, yes, keys match, but values do not // and we allow dups, so insert it somewhere else } // advance otherwise if ( ++n == m_numSlots ) n = 0; } // bail if not found if ( count >= m_numSlots ) { g_errno = ENOMEM; return log("htable: Could not add key. Table is full."); } if ( m_flags [ n ] == 0 ) { // inc count if we're the first m_numSlotsUsed++; // and store the key if ( m_ks == 4 ) ((int32_t *)m_keys)[n] = *(int32_t *)key; if ( m_ks == 8 ) ((int64_t *)m_keys)[n] = *(int64_t *)key; else memcpy ( m_keys + m_ks * n , key , m_ks ); } // insert the value for this key if ( val ) setValue ( n , val ); // caller sometimes wants this if ( slot ) *slot = n; // no longer empty m_flags[n] = 0x01; return true; }
void ScreenSetupView::resizeEvent(QResizeEvent* event) { setTableSize(); event->ignore(); }
void ScreenSetupView::setModel(ScreenSetupModel* model) { QTableView::setModel(model); setTableSize(); }