JX Application Framework
Loading...
Searching...
No Matches
Public Member Functions | Friends | List of all members
JRunArray< T > Class Template Reference

#include <JRunArray.h>

Inheritance diagram for JRunArray< T >:
[legend]

Public Member Functions

 JRunArray (const JSize blockSize=10)
 
 JRunArray (const JRunArray< T > &source)
 
 JRunArray (const JRunArray< T > &source, const JIndexRange &range)
 
 ~JRunArray () override
 
JRunArray< T > & operator= (const JRunArray< T > &source)
 
GetFirstItem () const override
 
GetLastItem () const override
 
void PrependItem (const T &data) override
 
void AppendItem (const T &data) override
 
void PrependItems (const T &data, const JSize count)
 
void AppendItems (const T &data, const JSize count)
 
void PrependSlice (const JRunArray< T > &source, const JIndexRange &range)
 
void AppendSlice (const JRunArray< T > &source, const JIndexRange &range)
 
void RemoveAll () override
 
bool AllItemsEqual (T *data=nullptr) const
 
JInteger SumItems (const JIndex startIndex, const JIndex endIndex, JInteger(*value)(const T &data)) const
 
bool FindPositiveSum (const JInteger requestedSum, const JIndex startIndex, JIndex *endIndex, JInteger *trueSum, JInteger(*value)(const T &data)) const
 
JListIterator< T > * NewIterator (const JListT::Position start=JListT::kStartAtBeginning, const JIndex index=0) override
 
JListIterator< T > * NewIterator (const JListT::Position start=JListT::kStartAtBeginning, const JIndex index=0) const override
 
JSize GetRunCount () const
 
JSize GetBlockSize () const
 
void SetBlockSize (const JSize newBlockSize)
 
- Public Member Functions inherited from JList< T >
 JList ()
 
 JList (const JList< T > &source)
 
 ~JList () override
 
void SetCompareFunction (const std::function< std::weak_ordering(const T &, const T &)> compareFn)
 
void CopyCompareFunction (const JList< T > &source)
 
void ClearCompareFunction ()
 
JListT::SortOrder GetSortOrder () const
 
void SetSortOrder (const JListT::SortOrder order)
 
bool IsSorted () const
 
- Public Member Functions inherited from JCollection
 JCollection ()
 
 JCollection (const JCollection &source)
 
 ~JCollection () override
 
JCollectionoperator= (const JCollection &source)
 
JSize GetItemCount () const
 
bool IsEmpty () const
 
bool IndexValid (const JIndex index) const
 
JIndex GetIndexFromEnd (const JIndex index) const
 
JString ToString () const override
 
- Public Member Functions inherited from JBroadcaster
 JBroadcaster ()
 
virtual ~JBroadcaster ()
 
JBroadcasteroperator= (const JBroadcaster &source)
 
bool HasSenders () const
 
JSize GetSenderCount () const
 
bool HasRecipients () const
 
JSize GetRecipientCount () const
 
template<class T >
void ListenTo (const JBroadcaster *sender, const std::function< void(const T &)> &f)
 

Friends

class JRunArrayIterator< T >
 

Additional Inherited Members

- Protected Member Functions inherited from JList< T >
std::function< std::weak_ordering(const T &, const T &)> * GetCompareFunction () const
 
void ListAssigned (const JList< T > &source)
 
void NotifyIterators (const JBroadcaster::Message &message)
 
- Protected Member Functions inherited from JCollection
void ItemAdded ()
 
void ItemRemoved ()
 
void SetItemCount (const JSize newItemCount)
 
- Protected Member Functions inherited from JBroadcaster
 JBroadcaster (const JBroadcaster &source)
 
void ListenTo (const JBroadcaster *sender)
 
void StopListening (const JBroadcaster *sender)
 
void ClearWhenGoingAway (const JBroadcaster *sender, void *pointerToMember)
 
void StopListening (const JBroadcaster *sender, const std::type_info &messageType)
 
template<class T >
void Send (JBroadcaster *recipient, const T &message)
 
template<class T >
void Broadcast (const T &message)
 
virtual void Receive (JBroadcaster *sender, const Message &message)
 
void SendWithFeedback (JBroadcaster *recipient, Message *message)
 
void BroadcastWithFeedback (Message *message)
 
virtual void ReceiveWithFeedback (JBroadcaster *sender, Message *message)
 
virtual void ReceiveGoingAway (JBroadcaster *sender)
 

Detailed Description

template<class T>
class JRunArray< T >

Interface for JRunArrayIterator class template

Constructor & Destructor Documentation

◆ JRunArray() [1/3]

template<class T >
JRunArray< T >::JRunArray ( const JSize  blockSize = 10)

JRunArray is a dynamic array optimized to conserve space where consecutive entries have the same value. Such a sequence of identical entries is called a run. Rather than storing N consecutive, identical entries, JRunArray stores the value once, along with the length of the run.

When using a JRunArray, operator== must be defined for the data type.

gcc 2.7.2 does not implement static data for template classes, without which we cannot provide an efficient implementation of Sort().

Implementation details:

A JArray is used to store the run lengths + actual items. Thus, JRunArrays cannot store objects, only intrinisic types.

◆ JRunArray() [2/3]

template<class T >
JRunArray< T >::JRunArray ( const JRunArray< T > &  source)

◆ JRunArray() [3/3]

template<class T >
JRunArray< T >::JRunArray ( const JRunArray< T > &  source,
const JIndexRange range 
)

◆ ~JRunArray()

template<class T >
JRunArray< T >::~JRunArray ( )
override

Member Function Documentation

◆ AllItemsEqual()

template<class T >
bool JRunArray< T >::AllItemsEqual ( T *  data = nullptr) const

◆ AppendItem()

template<class T >
void JRunArray< T >::AppendItem ( const T &  data)
overridevirtual

Implements JList< T >.

◆ AppendItems()

template<class T >
void JRunArray< T >::AppendItems ( const T &  data,
const JSize  count 
)

Append a run of items.

◆ AppendSlice()

template<class T >
void JRunArray< T >::AppendSlice ( const JRunArray< T > &  source,
const JIndexRange range 
)

◆ FindPositiveSum()

template<class T >
bool JRunArray< T >::FindPositiveSum ( const JInteger  requestedSum,
const JIndex  startIndex,
JIndex endIndex,
JInteger trueSum,
JInteger(*)(const T &data)  value 
) const

Returns the index of the item that causes the sum, starting from startIndex, to exceed requestedSum. *trueSum is the sum of the items up to, but not including, *endIndex. This gives the correct behavior for determining which interval was clicked by a cursor. To verify this, consider the case when all intervals have width one, and the left edge has coordinate zero.

Returns false if the sum through the end of the array does not exceeed requestedSum. In this case, *endIndex is the last item, and *trueSum is the sum up to, but not including, *endIndex.

This function requires that requestedSum be positive.

◆ GetBlockSize()

template<class T >
JSize JRunArray< T >::GetBlockSize ( ) const

Get the block size used by the underlying JArray.

◆ GetFirstItem()

template<class T >
T JRunArray< T >::GetFirstItem ( ) const
overridevirtual

Implements JList< T >.

◆ GetLastItem()

template<class T >
T JRunArray< T >::GetLastItem ( ) const
overridevirtual

Implements JList< T >.

◆ GetRunCount()

template<class T >
JSize JRunArray< T >::GetRunCount ( ) const

◆ NewIterator() [1/2]

template<class T >
JListIterator< T > * JRunArray< T >::NewIterator ( const JListT::Position  start = JListT::kStartAtBeginning,
const JIndex  index = 0 
) const
overridevirtual

Implements JList< T >.

◆ NewIterator() [2/2]

template<class T >
JListIterator< T > * JRunArray< T >::NewIterator ( const JListT::Position  start = JListT::kStartAtBeginning,
const JIndex  index = 0 
)
overridevirtual

Implements JList< T >.

◆ operator=()

template<class T >
JRunArray< T > & JRunArray< T >::operator= ( const JRunArray< T > &  source)

◆ PrependItem()

template<class T >
void JRunArray< T >::PrependItem ( const T &  data)
overridevirtual

Implements JList< T >.

◆ PrependItems()

template<class T >
void JRunArray< T >::PrependItems ( const T &  data,
const JSize  count 
)

Prepend a run of items.

◆ PrependSlice()

template<class T >
void JRunArray< T >::PrependSlice ( const JRunArray< T > &  source,
const JIndexRange range 
)

◆ RemoveAll()

template<class T >
void JRunArray< T >::RemoveAll ( )
overridevirtual

Implements JList< T >.

◆ SetBlockSize()

template<class T >
void JRunArray< T >::SetBlockSize ( const JSize  newBlockSize)

Set the block size used by the underlying JArray.

◆ SumItems()

template<class T >
JInteger JRunArray< T >::SumItems ( const JIndex  startIndex,
const JIndex  endIndex,
JInteger(*)(const T &data)  value 
) const

Returns the sum of the specified range of items, using the given accumulator function. We assume that the result is an integer because a JRunArray of floating point values would be silly, given the problem of round off errors.

Friends And Related Symbol Documentation

◆ JRunArrayIterator< T >

template<class T >
friend class JRunArrayIterator< T >
friend

The documentation for this class was generated from the following files: