int CTools::SortTable(TTable* _input, TTable& _output, int _column, bool _mode) { //g_pa->AddFunction("int CTools::SortTable(TTable* _input, TTable& _output, int _column, bool _mode)"); //g_pa->StartTiming(); //Create a vector of string that we will sort TTuple _maxtuple; std::string _max; if(_input->empty()) { return 1; } TTable::iterator _it=_input->begin(); _max.assign((*_it)[_column]); _maxtuple.assign( _it->begin(), _it->end() ); //Find Max for(; _it != _input->end(); ++_it) { if(std::lexicographical_compare(_max.begin(), _max.size()>LENGTH ? _max.begin()+LENGTH : _max.end(), (*_it)[_column].begin(), (*_it)[_column].size() > LENGTH ? (*_it)[_column].begin() + LENGTH : (*_it)[_column].end()) == _mode) { _max.assign((*_it)[_column]); _maxtuple.clear(); _maxtuple.assign( _it->begin(), _it->end() ); } } _input->remove(_maxtuple); _output.push_back(_maxtuple); //g_pa->StartTiming(); return SortTable(_input, _output, _column, _mode); }
//--------------------------------------------------------------------------- void __fastcall TMainForm::Table2MouseDown(TObject *Sender, TMouseButton Button, TShiftState Shift, int X, int Y) { int col,row; Table2->MouseToCell(X,Y,col,row); if (row==0) SortTable(Table2,col); }
//--------------------------------------------------------------------------- void __fastcall TMainForm::Table0MouseDown(TObject *Sender, TMouseButton Button, TShiftState Shift, int X, int Y) { AnsiString title; double lat,lon; int col,row; Table0->MouseToCell(X,Y,col,row); if (row==0) SortTable(Table0,col); }
void GenerateItemTable (CUniverse &Universe, CXMLElement *pCmdLine) { // Create the context SItemTableCtx Ctx; Ctx.pUniverse = &Universe; Ctx.pCmdLine = pCmdLine; // Compute the criteria TArray<CItemType *> Selection; SelectByCriteria(Ctx, pCmdLine->GetAttribute(CRITERIA_ATTRIB), &Selection); if (Selection.GetCount() == 0) { printf("No entries match criteria.\n"); return; } // Compute columns if (!CalcColumns(Ctx, pCmdLine)) return; // Sort the list SItemTypeList ItemList; SortTable(Ctx, Selection, &ItemList); // If by attribute, output categorized list if (pCmdLine->GetAttributeBool(BY_ATTRIBUTE_ATTRIB)) OutputByAttribute(Ctx, ItemList); else if (pCmdLine->GetAttributeBool(BY_SHIP_CLASS_ATTRIB)) OutputByShipClass(Ctx, ItemList, false); else if (pCmdLine->GetAttributeBool(BY_SHIP_CLASS_USAGE_ATTRIB)) OutputByShipClass(Ctx, ItemList, true); // Otherwise, just output a full table else { OutputHeader(Ctx); OutputTable(Ctx, ItemList); } printf("\n"); }
int main(int argc, char **argv) { FILE *fp; char str[MaxLineSize+1]; char str1[MaxLineSize+1] = "", str2[MaxLineSize+1] = ""; int count; if(argc < 3) { PrintUsage(); return 1; } if( !IsSorted(argv[1], (atoi(argv[2])-1), 'S') ) { SortTable(argv[1], atoi(argv[2]), 'S', "CountName.temp"); if( ( fp = fopen("CountName.temp", "r") ) == NULL ) { ErrMsg("Error: fopen failed.\n"); return false; } } else if( ( fp = fopen(argv[1], "r") ) == NULL ) { ErrMsg("Error: fopen failed.\n"); return false; } count = 1; for( TableRow theRow; theRow.Get(fp); ) { ColCpy( str2, theRow.Column(atoi(argv[2])-1) ); if( strcmp(str2, "") == 0 ) continue; if( strcmp(str1, str2) == 0 ) count++; else if( strcmp(str1, "") != 0 ) { printf("%s\t%d\n", str1, count ); count = 1; } strcpy( str1, str2 ); } if( strcmp(str1, "") != 0 ) printf("%s\t%d\n", str1, count ); fclose(fp); remove("CountName.temp"); return 0; }
void HashTable::GrowTable(){ //double the capacity Vector v_items; EnumerateTable(v_items); delete []mp_vector_array; m_number_elements=0; m_table_size<<=1; //left shift capacity by 1 mp_vector_array=new Vector[m_table_size]; int len=v_items.Size(); bool b_sort=mb_sorted; //remember whether or not it was sorted mb_sorted=false; //turn sorting off to make the adds much faster for(int i=0;i<len;i++){ Add((HashObject*)v_items.Get(i)); } if(b_sort){ SortTable(); } }
/** \details Test the SortTable (0x13), ExpandRow (0x59), CollapseRow(0x5a), GetCollapseState(0x6b) and SetCollapseState (0x6c) operations This function: -# Opens the Inbox folder and creates some test content -# Checks that the content is OK -# Applies a sort and categorisation -# Checks the results are as expected. -# Save away the Row ID and Insatnce Number for the first header -# Collapse the first category -# Checks the results are as expected. -# Save the "collapse state" -# Expand the first category again -# Checks the results are as expected -# Restore the saved "collapse state" -# Checks the results are as expected -# Cleans up \param mt pointer on the top-level mapitest structure \return true on success, otherwise false */ _PUBLIC_ bool mapitest_oxctable_Category(struct mapitest *mt) { mapi_object_t obj_htable; mapi_object_t obj_test_folder; struct mt_common_tf_ctx *context; uint32_t count = 0; uint32_t origcount = 0; bool ret = true; struct SSortOrderSet criteria; uint64_t inst_id = 0; uint64_t inst_num = 0; struct SPropTagArray *SPropTagArray; struct SRowSet SRowSet; uint32_t rowcount = 0; uint32_t Numerator = 0; uint32_t Denominator = 0; struct SBinary_short collapseState; /* Step 1. Logon */ if (! mapitest_common_setup(mt, &obj_htable, &count)) { return false; } /* Step 2. Get the test folder */ context = mt->priv; mapi_object_init(&(obj_test_folder)); GetContentsTable(&(context->obj_test_folder), &(obj_test_folder), 0, &origcount); if (GetLastError() != MAPI_E_SUCCESS) { mapitest_print_retval(mt, "GetContentsTable"); ret = false; goto cleanup; } if (origcount != 10) { mapitest_print(mt, "* %-35s: unexpected count (%i)\n", "GetContentsTable", count); /* This isn't a hard error for this test though, because it might be from a previous test failure. Clean up and try again */ } /* We need the header row InstanceId to fold/unfold the headers */ SPropTagArray = set_SPropTagArray(mt->mem_ctx, 0x6, PR_SENDER_NAME, PR_BODY, PR_LAST_MODIFICATION_TIME, PR_SUBJECT, PR_INST_ID, PR_INSTANCE_NUM); SetColumns(&(obj_test_folder), SPropTagArray); MAPIFreeBuffer(SPropTagArray); mapitest_print_retval(mt, "SetColumns"); if (GetLastError() != MAPI_E_SUCCESS) { ret = false; goto cleanup; } /* Apply a categorised sort */ memset(&criteria, 0x0, sizeof (struct SSortOrderSet)); criteria.cSorts = 1; criteria.cCategories = 1; criteria.cExpanded = 1; criteria.aSort = talloc_array(mt->mem_ctx, struct SSortOrder, criteria.cSorts); criteria.aSort[0].ulPropTag = PR_SENDER_NAME; criteria.aSort[0].ulOrder = TABLE_SORT_ASCEND; SortTable(&(obj_test_folder), &criteria); mapitest_print_retval(mt, "SortTable"); if (GetLastError() != MAPI_E_SUCCESS) { ret = false; goto cleanup; } rowcount = 2 * origcount; QueryRows(&(obj_test_folder), rowcount, TBL_ADVANCE, &SRowSet); mapitest_print_retval(mt, "QueryRows"); if (GetLastError() != MAPI_E_SUCCESS) { ret = false; goto cleanup; } /* Checks the results are as expected */ QueryPosition(&(obj_test_folder), &Numerator, &Denominator); mapitest_print_retval(mt, "QueryPosition"); if (GetLastError() != MAPI_E_SUCCESS) { ret = false; goto cleanup; } /* the categories are expanded, and there are six unique senders, so there are six extra rows - one for each header row */ if (Denominator != origcount + 6) { mapitest_print(mt, "* %-35s: unexpected count (%i)\n", "QueryPosition", Numerator); ret = false; goto cleanup; } /* save away ID/instance values for first row header */ inst_id = (*(const uint64_t *)get_SPropValue_data(&(SRowSet.aRow[0].lpProps[4]))); inst_num = (*(const uint32_t *)get_SPropValue_data(&(SRowSet.aRow[0].lpProps[5]))); /* Collapse a row header */ CollapseRow(&(obj_test_folder), inst_id, &rowcount); mapitest_print_retval(mt, "CollapseRow"); if (GetLastError() != MAPI_E_SUCCESS) { ret = false; goto cleanup; } /* Checks the results are as expected */ QueryPosition(&(obj_test_folder), &Numerator, &Denominator); mapitest_print_retval(mt, "QueryPosition"); if (GetLastError() != MAPI_E_SUCCESS) { ret = false; goto cleanup; } /* there are still six unique headers, but half of the real entries are under the first header (usually 10, unless we have some other rubbish hanging around), and when we collapse the first header row, that half disappear */ if (Denominator != origcount/2 + 6) { mapitest_print(mt, "* %-35s: unexpected count (%i)\n", "QueryPosition", Denominator); ret = false; goto cleanup; } /* Save the table collapse state */ GetCollapseState(&(obj_test_folder), inst_id, inst_num, &collapseState); mapitest_print_retval(mt, "GetCollapseState"); if (GetLastError() != MAPI_E_SUCCESS) { ret = false; goto cleanup; } /* Expand a category */ ExpandRow(&(obj_test_folder), inst_id, 20, &SRowSet, &rowcount); mapitest_print_retval(mt, "ExpandRow"); if (GetLastError() != MAPI_E_SUCCESS) { ret = false; goto cleanup; } /* Checks the results are as expected */ QueryPosition(&(obj_test_folder), &Numerator, &Denominator); mapitest_print_retval(mt, "QueryPosition"); if (GetLastError() != MAPI_E_SUCCESS) { ret = false; goto cleanup; } /* we've expanded the first header row, so we now get all the entries plus the 6 headers */ if (Denominator != origcount + 6) { mapitest_print(mt, "* %-35s: unexpected count (%i)\n", "QueryPosition", Denominator); ret = false; goto cleanup; } /* Restore the collapse state */ SetCollapseState(&(obj_test_folder), &collapseState); mapitest_print_retval(mt, "SetCollapseState"); if (GetLastError() != MAPI_E_SUCCESS) { ret = false; goto cleanup; } /* Checks the results are as expected */ QueryPosition(&(obj_test_folder), &Numerator, &Denominator); mapitest_print_retval(mt, "QueryPosition"); if (GetLastError() != MAPI_E_SUCCESS) { ret = false; goto cleanup; } /* back to the situation with the first heading collapsed */ if (Denominator != origcount/2 + 6) { mapitest_print(mt, "* %-35s: unexpected count (%i)\n", "QueryPosition", Denominator); ret = false; goto cleanup; } cleanup: /* Release */ mapi_object_release(&obj_htable); mapi_object_release(&(obj_test_folder)); mapitest_common_cleanup(mt); return ret; }
/// Compress and pack table into an UpdateMsg and return it UpdateMsg *SRtable::PackTable(POSE_TimeType pvt, POSE_TimeType *maxSR) { //check me #ifdef SR_SANITIZE sanitize(); #endif register int i; int packSize = 0, nEntries = 0, entryIdx = 0; POSE_TimeType nBkts = 0; POSE_TimeType destBkt; // which bucket? SRentry *tmp; if (pvt == POSE_UnsetTS) destBkt = b; else destBkt = (pvt-offset)/size_b; SortTable(); nBkts = destBkt; if (destBkt >= b) { tmp = overflow; while (tmp && (tmp->timestamp < pvt)) { nEntries++; tmp = tmp->next; } nBkts = b-1; } for (i=0; i<=nBkts; i++) { tmp = buckets[i]; while (tmp) { (*maxSR) = tmp->timestamp; if (tmp->sends != tmp->recvs) nEntries++; tmp = tmp->next; } } packSize = nEntries * sizeof(SRentry); UpdateMsg *um = new (packSize, 0) UpdateMsg; for (i=0; i<=nBkts; i++) { tmp = buckets[i]; while (tmp) { if (tmp->sends != tmp->recvs) { um->SRs[entryIdx] = *tmp; entryIdx++; } tmp = tmp->next; } } // arguably redundant um->maxSR=*maxSR; if (destBkt >= b) { tmp = overflow; while (tmp && (tmp->timestamp < pvt)) { if (tmp->sends != tmp->recvs) { um->SRs[entryIdx] = *tmp; entryIdx++; } tmp = tmp->next; } } for (i=0; i<entryIdx-1; i++) { if (um->SRs[i].timestamp > um->SRs[i+1].timestamp) CkPrintf("WARNING: SRtable sorting code is broken!\n"); } CkAssert(entryIdx <= nEntries); //if ((um->SRs[0].timestamp < pvt) || (pvt == POSE_UnsetTS)) //CkPrintf("PE %d sending %d sr entries earliest=%d pvt=%d\n", CkMyPe(), //entryIdx, um->SRs[0].timestamp, pvt); um->numEntries = entryIdx; #ifdef SR_SANITIZE sanitize(); #endif return um; }