TestFloatTable::TestFloatTable ( JFloatTableData* data, JXMenuBar* menuBar, JXScrollbarSet* scrollbarSet, JXContainer* enclosure, const HSizingOption hSizing, const VSizingOption vSizing, const JCoordinate x, const JCoordinate y, const JCoordinate w, const JCoordinate h ) : JXFloatTable(data, 4, scrollbarSet, enclosure, hSizing,vSizing, x,y, w,h) { JIndex i,j; itsMouseAction = kInsertCol; (GetEditMenuHandler())->AppendEditMenu(menuBar); itsTableMenu = menuBar->AppendTextMenu(kTableMenuTitleStr); itsTableMenu->SetMenuItems(kTableMenuStr); itsTableMenu->SetUpdateAction(JXMenu::kDisableNone); ListenTo(itsTableMenu); itsSizeMenu = new JXFontSizeMenu(JGetDefaultFontName(), "Size", menuBar, kFixedLeft, kFixedTop, 0,0, 10,10); assert( itsSizeMenu != NULL ); menuBar->AppendMenu(itsSizeMenu); ListenTo(itsSizeMenu); itsStyleMenu = new JXStyleTableMenu(this, menuBar, kFixedLeft, kFixedTop, 0,0, 10,10); assert( itsStyleMenu != NULL ); menuBar->AppendMenu(itsStyleMenu); JSize fontSize; const JString& fontName = GetFont(&fontSize); itsSizeMenu->SetFontName(fontName); itsSizeMenu->SetFontSize(fontSize); data->AppendRows(kInitRowCount); data->AppendCols(kInitColCount); JKLRand r; for (j=1; j<=kInitColCount; j++) { for (i=1; i<=kInitRowCount; i++) { data->SetElement(i,j, r.UniformClosedProb()); } } }
void TestData ( Test2DPlotDirector* dir ) { JIndex i; JX2DPlotWidget* plot = dir->GetPlotWidget(); plot->ShowLegend(); JArray<JFloat> x(100),y(100), xPErr(101),xMErr(101), yPErr(101), yMErr(101); JKLRand r; JFloat delta = kJPi/50.0; for (i=0; i<=100; i++) { x.AppendElement(i*delta); y.AppendElement(sin(i*delta)); xPErr.AppendElement(r.UniformDouble(0.0, 0.1)); xMErr.AppendElement(r.UniformDouble(0.0, 0.1)); yPErr.AppendElement(r.UniformDouble(0.0, 0.1)); yMErr.AppendElement(r.UniformDouble(0.0, 0.1)); } J2DPlotData* data; JBoolean ok = J2DPlotData::Create(&data, x, y, kJFalse); assert( ok ); ok = data->SetXErrors(xPErr, xMErr); assert( ok ); ok = data->SetYErrors(yPErr, yMErr); assert( ok ); plot->AddCurve(data, kJTrue, "sin(x)", kJTrue, kJTrue); x.RemoveAll(); y.RemoveAll(); delta = kJPi/5000.0; for (i=0; i<=10000; i++) { x.AppendElement(i*delta); y.AppendElement(cos(i*delta)); } plot->AddCurve(x, y, kJFalse, "cos(x)", &i, kJTrue, kJFalse); plot->SetTitle("Error bars"); }
void RemoveRand ( JHashTable< JStrValue<int> >* const table, const JSize listLength, const JHashValue* const hashList, const JStrValue<int>* const valueList, int* const countList ) { const JIndex firstEl = gRand.UniformLong(0, listLength-1); JIndex el = firstEl; while (countList[el] == 0) { ++el; if (el == firstEl) { if (table->GetElementCount() != 0) { PrintError(__LINE__); } return; } } RemoveElement(el, table, kElementNum, hashList, valueList, countList); }
void JXTipOfTheDayDialog::ParseTips() { const JString& data = JGetString(kStringID); itsTipList->CleanOut(); const JSize len = strlen(kDelimiter); JIndex j = 1, i = j; while (data.LocateNextSubstring(kDelimiter, &j)) { if (j > i) { AddTip(data.GetSubstring(i, j-1)); } j += len; i = j; } if (i <= data.GetLength()) { AddTip(data.GetSubstring(i, data.GetLength())); } assert( !itsTipList->IsEmpty() ); itsTipIndex = theRandomGenerator.UniformLong(1, itsTipList->GetElementCount()); DisplayTip(); }
void SearchRand ( const JHashTable< JStrValue<int> >* const table, const JSize listLength, const JHashValue* const hashList, const JStrValue<int>* const valueList, const int* const countList ) { const JIndex el = gRand.UniformLong(0, listLength-1); SearchElement(el, table, listLength, hashList, valueList, countList); }
void RemoveElement ( const JSize el, JHashTable< JStrValue<int> >* const table, const JSize listLength, const JHashValue* const hashList, const JStrValue<int>* const valueList, int* const countList ) { JHashCursor< JStrValue<int> > cursor(table, hashList[el]); JSize count = 0; while ( cursor.NextHash() ) { ++count; if ( !cursor.IsFull() || cursor.GetHashValue() != hashList[el]) { PrintError(__LINE__); } } if (count == 0) { return; } const JSize deleteNum = gRand.UniformLong(1, count); cursor.Reset(); for (JIndex i=1;i<=deleteNum;i++) { if (!cursor.NextHash() ) { PrintError(__LINE__); cout << " Count = " << count << ", deleteNum = " << deleteNum << endl; cout << " Error on cycle " << i << endl; return; } } cursor.Remove(); --countList[el]; }
int main() { cout << "Beginning JHashTable test. No news is good news" << endl; // TableState experiment = CreateTableState; JHashTable< JStrValue<int> > table; // Generate hash list JHashValue hashList[kElementNum]; JIndex i; for (i=0;i<kElementNum;i++) { hashList[i] = gRand.UniformInt32(); } // Generate key list const JCharacter* keyList[kElementNum]; for (i=0;i<kElementNum;i++) { keyList[i] = "Lazy key"; } // Generate value list JStrValue<int> valueList[kElementNum]; for (i=0;i<kElementNum;i++) { valueList[i].key = "Lazy key"; valueList[i].value = gRand.UniformInt32(); } // Generate storage count list int countList[kElementNum]; for (i=0;i<kElementNum;i++) { countList[i] = 0; } // JSize goal = 100; for (i=0;i<10000;i++) { JFloat prob = gRand.UniformClosedProb(); if (prob < 0.1) { StoreRand(&table, kElementNum, hashList, valueList, countList); } else if (prob < 0.2) { RemoveRand(&table, kElementNum, hashList, valueList, countList); } else { SearchRand(&table, kElementNum, hashList, valueList, countList); } } //cout << "\nSecond half\n" << endl; for (i=0;i<10000;i++) { JFloat prob = gRand.UniformClosedProb(); if (prob < 0.05) { StoreRand(&table, kElementNum, hashList, valueList, countList); } else if (prob < 0.15) { RemoveRand(&table, kElementNum, hashList, valueList, countList); } else { SearchRand(&table, kElementNum, hashList, valueList, countList); } } cout << "Finished JHashTable test. If nothing printed out, it passed" << endl; cout << "\n Size: " << table.GetTableSize() << endl; cout << "\nElement count: " << table.GetElementCount() << endl; cout << " Load count: " << table.GetLoadCount() << endl; cout << "\nFill factor: " << table.GetFillFactor() << endl; cout << "Load factor: " << table.GetLoadFactor() << endl; return 0; }