void wxListBox::SetString(unsigned int n, const wxString& s) { wxCHECK_RET( !IsSorted(), wxT("can't set string in sorted listbox") ); if ( IsSorted() ) (*m_strings.sorted)[n] = s; else (*m_strings.unsorted)[n] = s; GetListPeer()->UpdateLine(n); }
int wxChoice::DoInsertItems(const wxArrayStringsAdapter & items, unsigned int pos, void **clientData, wxClientDataType type) { const unsigned int numItems = items.GetCount(); for( unsigned int i = 0; i < numItems; ++i, ++pos ) { unsigned int idx; #if wxUSE_STL if ( IsSorted() ) { wxArrayString::iterator insertPoint = std::lower_bound( m_strings.begin(), m_strings.end(), items[i] ); idx = insertPoint - m_strings.begin(); m_strings.insert( insertPoint, items[i] ); } else #endif // wxUSE_STL { idx = pos; m_strings.Insert( items[i], idx ); } m_popUpMenu->Insert( idx, i+1, items[i] ); m_datas.Insert( NULL, idx ); AssignNewItemClientData(idx, clientData, i, type); } m_peer->SetMaximum( GetCount() ); return pos - 1; }
int wxListBox::DoInsertItems(const wxArrayStringsAdapter& items, unsigned int pos, void **clientData, wxClientDataType type) { int idx = wxNOT_FOUND; unsigned int startpos = pos; const unsigned int numItems = items.GetCount(); for ( unsigned int i = 0; i < numItems; ++i ) { const wxString& item = items[i]; idx = IsSorted() ? m_strings.sorted->Add(item) : (m_strings.unsorted->Insert(item, pos), pos++); m_itemsClientData.Insert(NULL, idx); AssignNewItemClientData(idx, clientData, i, type); GetListPeer()->ListInsert(startpos+i); OnItemInserted(idx); } GetListPeer()->UpdateLineToEnd(startpos); UpdateOldSelections(); return idx; }
int wxChoice::DoInsertItems(const wxArrayStringsAdapter & items, unsigned int pos, void **clientData, wxClientDataType type) { wxCHECK_MSG( m_widget != NULL, -1, wxT("invalid control") ); wxASSERT_MSG( !IsSorted() || (pos == GetCount()), wxT("In a sorted choice data could only be appended")); const int count = items.GetCount(); int n = wxNOT_FOUND; for ( int i = 0; i < count; ++i ) { n = pos + i; // If sorted, use this wxSortedArrayStrings to determine // the right insertion point if (m_strings) n = m_strings->Add(items[i]); GTKInsertComboBoxTextItem( n, items[i] ); m_clientData.Insert( NULL, n ); AssignNewItemClientData(n, clientData, i, type); } InvalidateBestSize(); return n; }
void wxListBox::DoInsertItems(const wxArrayString& items, int pos) { // the position of the item being added to a sorted listbox can't be // specified wxCHECK_RET( !IsSorted(), _T("can't insert items into sorted listbox") ); size_t count = items.GetCount(); for ( size_t n = 0; n < count; n++ ) { m_strings->Insert(items[n], pos + n); m_itemsClientData.Insert(NULL, pos + n); } // the number of items has changed so we might have to show the scrollbar m_updateScrollbarY = true; // the max width also might have changed - just recalculate it instead of // keeping track of it here, this is probably more efficient for a typical // use pattern RefreshHorzScrollbar(); // note that we have to refresh all the items after the ones we inserted, // not just these items RefreshFromItemToEnd(pos); }
bool wxChoice::Create( wxWindow *parent, wxWindowID id, const wxPoint &pos, const wxSize &size, int n, const wxString choices[], long style, const wxValidator& validator, const wxString &name ) { if (!PreCreation( parent, pos, size ) || !CreateBase( parent, id, pos, size, style, validator, name )) { wxFAIL_MSG( wxT("wxChoice creation failed") ); return false; } if ( IsSorted() ) { // if our m_strings != NULL, Append() will check for it and insert // items in the correct order m_strings = new wxSortedArrayString; } m_widget = gtk_combo_box_new_text(); g_object_ref(m_widget); Append(n, choices); m_parent->DoAddChild( this ); PostCreation(size); g_signal_connect_after (m_widget, "changed", G_CALLBACK (gtk_choice_changed_callback), this); return true; }
void PointerListTest::SortTest() { for (int i = 0; i < 10; i ++) { _PointerList_ list; Initialize(list, i); _PointerList_ clone(list); assert(Equals(list, clone)); assert(clone.Owning() == false); list.SortItems(Item::Compare); assert(IsSorted(list)); int lastItem = clone.CountItems()-1; bool hasItems = clone.CountItems() > 0; Item* item = NULL; if (hasItems) { item = (Item*)clone.ItemAt(0); } // HSortItems seems to put the first item at the end of the list // and sort the rest. clone.HSortItems(Item::Compare); assert(IsHSorted(clone)); assert(!hasItems || item == (Item*)clone.ItemAt(lastItem)); MakeEmpty(list); } }
void wxListBox::SetString(int n, const wxString& s) { wxCHECK_RET( !IsSorted(), _T("can't set string in sorted listbox") ); (*m_strings)[n] = s; if ( HasHorzScrollbar() ) { // we need to update m_maxWidth as changing the string may cause the // horz scrollbar [dis]appear wxCoord width; GetTextExtent(s, &width, NULL); // it might have increased if the new string is long if ( width > m_maxWidth ) { m_maxWidth = width; m_maxWidthItem = n; m_updateScrollbarX = true; } // or also decreased if the old string was the longest one else if ( n == m_maxWidthItem ) { RefreshHorzScrollbar(); } } RefreshItem(n); }
void PointerListTest::SortTestWithState() { gData = (void*)0x4711; for (int i = FROM; i < (TO+1); i ++) { BStopWatch* watch = new BStopWatch("Initialize"); _PointerList_ list; Initialize(list, i); delete watch; watch = new BStopWatch("Clone"); _PointerList_ clone(list); delete watch; assert(Equals(list, clone)); assert(clone.Owning() == false); watch = new BStopWatch("SortItems"); list.SortItems(::Compare, gData); delete watch; assert(IsSorted(list)); watch = new BStopWatch("SortItems (sorted list)"); list.SortItems(::Compare, gData); delete watch; assert(IsSorted(list)); int lastItem = clone.CountItems()-1; bool hasItems = clone.CountItems() > 0; Item* item = NULL; if (hasItems) { item = (Item*)clone.ItemAt(0); } // HSortItems seems to put the first item at the end of the list // and sort the rest. watch = new BStopWatch("HSortItems"); clone.HSortItems(Compare, gData); delete watch; assert(IsHSorted(clone)); assert(!hasItems || item == (Item*)clone.ItemAt(lastItem)); watch = new BStopWatch("MakeEmpty"); MakeEmpty(list); delete watch; } }
int fsaFile::WriteXML(RGFile &file) { if(!IsSorted()) { Sort(); } rewindDirEntries(); fsa2XML::WriteXML(this,&file); return 0; }
int wxChoice::FindString( const wxString& s, bool bCase ) const { #if !wxUSE_STD_CONTAINERS // Avoid assert for non-default args passed to sorted array Index if ( IsSorted() ) bCase = true; #endif return m_strings.Index( s , bCase ) ; }
static inline void SetNumAllocated (TRI_fulltext_list_t* const list, const uint32_t value) { uint32_t* head = (uint32_t*) list; if (IsSorted(list)) { *head = value | SORTED_BIT; } else { *head = value & ~SORTED_BIT; } }
void wxListBox::FreeData() { if ( IsSorted() ) m_strings.sorted->Clear(); else m_strings.unsorted->Clear(); m_itemsClientData.Clear(); GetListPeer()->ListClear(); }
int wxListBox::DoInsertItems(const wxArrayStringsAdapter & items, unsigned int pos, void **clientData, wxClientDataType type) { long lIndex = 0; LONG lIndexType = 0; bool incrementPos = false; if (IsSorted()) lIndexType = LIT_SORTASCENDING; else if (pos == GetCount()) lIndexType = LIT_END; else { lIndexType = (LONG)pos; incrementPos = true; } int n = wxNOT_FOUND; unsigned int count = items.GetCount(); for (unsigned int i = 0; i < count; i++) { n = (int)::WinSendMsg(GetHwnd(), LM_INSERTITEM, (MPARAM)lIndexType, (MPARAM)items[i].wx_str()); if (n < 0) { wxLogLastError(_T("WinSendMsg(LM_INSERTITEM)")); n = wxNOT_FOUND; break; } ++m_nNumItems; #if wxUSE_OWNER_DRAWN if (HasFlag(wxLB_OWNERDRAW)) { wxOwnerDrawn* pNewItem = CreateItem(n); // dummy argument wxScreenDC vDc; // FIXME: is it really needed here? pNewItem->SetName(items[i]); m_aItems.Insert(pNewItem, n); pNewItem->SetFont(GetFont()); } #endif AssignNewItemClientData(n, clientData, i, type); if (incrementPos) ++lIndexType; } return n; } // end of wxListBox::DoInsertAppendItemsWithData
static void SortList(TRI_fulltext_list_t* list) { if (IsSorted(list)) { // nothing to do return; } uint32_t numEntries = GetNumEntries(list); if (numEntries > 1) { // only sort if more than one elements qsort(GetStart(list), numEntries, sizeof(TRI_fulltext_list_entry_t), &CompareEntries); } SetIsSorted(list, true); }
wxListBox::~wxListBox() { m_blockEvents = true; FreeData(); m_blockEvents = false; // make sure no native events get sent to a object in destruction SetPeer(NULL); if ( IsSorted() ) delete m_strings.sorted; else delete m_strings.unsorted; m_strings.sorted = NULL; }
void wxListBox::DoDeleteOneItem(unsigned int n) { wxCHECK_RET( IsValid(n), wxT("invalid index in wxListBox::Delete") ); m_blockEvents = true; if ( IsSorted() ) m_strings.sorted->RemoveAt(n); else m_strings.unsorted->RemoveAt(n); m_itemsClientData.RemoveAt(n); GetListPeer()->ListDelete( n ); m_blockEvents = false; UpdateOldSelections(); }
int wxListBox::DoInsertItems(const wxArrayStringsAdapter& items, unsigned int pos, void **clientData, wxClientDataType type) { int idx = wxNOT_FOUND; unsigned int startpos = pos; const unsigned int numItems = items.GetCount(); #if defined(__INTEL_COMPILER) && 1 /* VDM auto patch */ # pragma ivdep # pragma swp # pragma unroll # pragma prefetch # if 0 # pragma simd noassert # endif #endif /* VDM auto patch */ for ( unsigned int i = 0; i < numItems; ++i ) { const wxString& item = items[i]; idx = IsSorted() ? m_strings.sorted->Add(item) : (m_strings.unsorted->Insert(item, pos), pos++); m_itemsClientData.Insert(NULL, idx); AssignNewItemClientData(idx, clientData, i, type); GetListPeer()->ListInsert(startpos+i); OnItemInserted(idx); } GetListPeer()->UpdateLineToEnd(startpos); // Inserting the items may scroll the listbox down to show the last // selected one but we don't want to do it as it could result in e.g. the // first items of a listbox be hidden immediately after its creation so // show the first selected item instead. Ideal would probably be to // preserve the old selection unchanged, in fact, but I don't know how to // get the first visible item so for now do at least this. SetFirstItem(startpos); UpdateOldSelections(); return idx; }
void BogoSort(std::vector<int> vals) { srand(time(NULL)); while(!IsSorted(vals)) { for(int i = 0; i < vals.size(); ++i) { int temp = vals[i]; int target = rand() % vals.size(); vals[i] = vals[target]; vals[target] = temp; } for(int n : vals) std::cout << n << " "; std::cout << "\n"; } }
int wxListBox::DoAppendOnly(const wxString& item) { size_t index; if ( IsSorted() ) { m_strings->Add(item); m_strings->Sort(wxListBoxSortNoCase); index = m_strings->Index(item); } else { index = m_strings->GetCount(); m_strings->Add(item); } return index; }
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; }
bool wxListBox::Create( wxWindow *parent, wxWindowID id, const wxPoint& pos, const wxSize& size, int n, const wxString choices[], long style, const wxValidator& validator, const wxString& name ) { DontCreatePeer(); m_blockEvents = false; if ( ! (style & wxNO_BORDER) ) style = (style & ~wxBORDER_MASK) | wxSUNKEN_BORDER ; wxASSERT_MSG( !(style & wxLB_MULTIPLE) || !(style & wxLB_EXTENDED), wxT("only a single listbox selection mode can be specified") ); if ( !wxListBoxBase::Create( parent, id, pos, size, style & ~(wxHSCROLL | wxVSCROLL), validator, name ) ) return false; if ( IsSorted() ) m_strings.sorted = new wxSortedArrayString; else m_strings.unsorted = new wxArrayString; SetPeer(wxWidgetImpl::CreateListBox( this, parent, id, pos, size, style, GetExtraStyle() )); MacPostControlCreate( pos, size ); m_textColumn = GetListPeer()->InsertTextColumn(0,wxEmptyString); Append(n, choices); // Needed because it is a wxControlWithItems SetInitialSize( size ); return true; }
int wxChoice::DoInsertItems(const wxArrayStringsAdapter& items , unsigned int pos , void **clientData , wxClientDataType type ) { int nIndex = wxNOT_FOUND; LONG nIndexType = 0; bool incrementPos = false; if ( IsSorted() ) nIndexType = LIT_SORTASCENDING; else if (pos == GetCount()) nIndexType = LIT_END; else { nIndexType = pos; incrementPos = true; } const unsigned int count = items.GetCount(); for( unsigned int i = 0; i < count; ++i ) { nIndex = (int)::WinSendMsg( GetHwnd() ,LM_INSERTITEM ,(MPARAM)nIndexType ,(MPARAM)items[i].wx_str() ); if (nIndex < 0) { nIndex = wxNOT_FOUND; break; } AssignNewItemClientData(nIndex, clientData, i, type); if (incrementPos) ++nIndexType; } return nIndex; } // end of wxChoice::DoInsertAppendItemsWithData
void fsaFile::Sort() { const int MAX = 2000; int n = dirEntryCount(); fsaDirEntry *pEntries[MAX]; rewindDirEntries(); memset(pEntries,0,sizeof(pEntries)); if((n > MAX) && !IsSorted()) { throw new Exception("Too many dir entries in fsa data, cannot sort"); } for(int i = 0; i < n; i++) { pEntries[i] = nextDirEntry(); } qsort((void *) pEntries,sizeof(fsaDirEntry *),(size_t) n, CompareEntry); _vecDirEntry.clear(); for(int i = 0; i < n; i++) { _vecDirEntry.push_back(pEntries[i]); } }
void PointerListTest::BinarySearchTest() { _PointerList_ list; Initialize(list, 10); list.SortItems(Item::Compare); assert(IsSorted(list)); gData = (void*)0x4711; Item notInListLow(NOT_USED_ID); Item notInListHigh(NOT_USED_ID_HIGH); for (int32 i = 0; i < 10; i ++) { Item* item = (Item*)list.ItemAt(i); assert(item != NULL); Item* found = (Item*)list.BinarySearch(item, Item::Compare); assert(item->Equals(found)); found = (Item*)list.BinarySearch(item, ::Compare, gData); assert(item->Equals(found)); found = (Item*)list.BinarySearch(¬InListLow, Item::Compare); assert(found == NULL); found = (Item*)list.BinarySearch(¬InListLow, ::Compare, gData); assert(found == NULL); found = (Item*)list.BinarySearch(¬InListHigh, Item::Compare); assert(found == NULL); found = (Item*)list.BinarySearch(¬InListHigh, ::Compare, gData); assert(found == NULL); } MakeEmpty(list); }
int wxChoice::DoInsertItems(const wxArrayStringsAdapter & items, unsigned int pos, void **clientData, wxClientDataType type) { const unsigned int numItems = items.GetCount(); for( unsigned int i = 0; i < numItems; ++i, ++pos ) { unsigned int idx; #if wxUSE_STD_CONTAINERS if ( IsSorted() ) { wxArrayString::iterator insertPoint = std::lower_bound( m_strings.begin(), m_strings.end(), items[i] ); idx = insertPoint - m_strings.begin(); m_strings.insert( insertPoint, items[i] ); } else #endif // wxUSE_STD_CONTAINERS { idx = pos; m_strings.Insert( items[i], idx ); } wxString text = items[i]; if (text == wxEmptyString) text = " "; // menu items can't have empty labels m_popUpMenu->Insert( idx, i+1, text ); m_datas.Insert( NULL, idx ); AssignNewItemClientData(idx, clientData, i, type); } DoAfterItemCountChange(); return pos - 1; }
template <class IterT> inline bool IsSorted(IterT beg, IterT end) { return IsSorted(beg, end, less<typename iterator_traits<IterT>::value_type>()); }
int wxListBox::FindString(const wxString& s, bool bCase) const { return IsSorted() ? m_strings.sorted->Index(s, bCase) : m_strings.unsorted->Index(s, bCase); }
wxString wxListBox::GetString(unsigned int n) const { return IsSorted() ? m_strings.sorted->Item(n) : m_strings.unsorted->Item(n); }
unsigned int wxListBox::GetCount() const { return IsSorted() ? m_strings.sorted->size() : m_strings.unsorted->size(); }