aboutsummaryrefslogtreecommitdiff
path: root/mp/src/public/tier1/UtlSortVector.h
diff options
context:
space:
mode:
authorJoe Ludwig <[email protected]>2014-05-15 13:59:18 -0700
committerJoe Ludwig <[email protected]>2014-05-15 13:59:18 -0700
commit53e78c503e6e9c7d15e2eefc480755fe37dd7077 (patch)
treec8cc106eb4c0a2b2b5d79f534f2facb0514f5f55 /mp/src/public/tier1/UtlSortVector.h
parentAdded many shader source files (diff)
downloadsource-sdk-2013-53e78c503e6e9c7d15e2eefc480755fe37dd7077.tar.xz
source-sdk-2013-53e78c503e6e9c7d15e2eefc480755fe37dd7077.zip
General:
* Upgraded Steamworks SDK to v1.29 * Fixed mod compatibility problem with Multiplayer Base that was introduced in September. * In Hammer, while using the Vertex Tool, pressing CTRL+B will snap selected vertices to the grid. Virtual Reality: * Mods that support virtual reality now need to have a line in gameinfo.txt that says “supportsvr 1”. This indicates to gameui and engine that certain UI should be enabled. * VR-enabled mods will now start up in VR mode when launched from Steam’s VR mode. Windows: * Upgraded to Visual Studio 2013. If you need to build projects for VS 2010, add /2010 to your VPC command line. OSX: * Upgraded to XCode 5.
Diffstat (limited to 'mp/src/public/tier1/UtlSortVector.h')
-rw-r--r--mp/src/public/tier1/UtlSortVector.h126
1 files changed, 110 insertions, 16 deletions
diff --git a/mp/src/public/tier1/UtlSortVector.h b/mp/src/public/tier1/UtlSortVector.h
index 76026925..b5bfef53 100644
--- a/mp/src/public/tier1/UtlSortVector.h
+++ b/mp/src/public/tier1/UtlSortVector.h
@@ -1,4 +1,4 @@
-//========= Copyright Valve Corporation, All rights reserved. ============//
+//===== Copyright � 1996-2005, Valve Corporation, All rights reserved. ======//
//
// $Header: $
// $NoKeywords: $
@@ -45,31 +45,49 @@ public:
template <class T, class LessFunc = CUtlSortVectorDefaultLess<T>, class BaseVector = CUtlVector<T> >
class CUtlSortVector : public BaseVector
{
+ typedef BaseVector BaseClass;
public:
-
- // constructor
+ /// constructor
CUtlSortVector( int nGrowSize = 0, int initSize = 0 );
CUtlSortVector( T* pMemory, int numElements );
- // inserts (copy constructs) an element in sorted order into the list
+ /// inserts (copy constructs) an element in sorted order into the list
int Insert( const T& src );
- // Finds an element within the list using a binary search
- int Find( const T& search ) const;
- int FindLessOrEqual( const T& search ) const;
- int FindLess( const T& search ) const;
+ /// inserts (copy constructs) an element in sorted order into the list if it isn't already in the list
+ int InsertIfNotFound( const T& src );
+
+ /// Finds an element within the list using a binary search. These are templatized based upon the key
+ /// in which case the less function must handle the Less function for key, T and T, key
+ template< typename TKey >
+ int Find( const TKey& search ) const;
+ template< typename TKey >
+ int FindLessOrEqual( const TKey& search ) const;
+ template< typename TKey >
+ int FindLess( const TKey& search ) const;
- // Removes a particular element
+ /// Removes a particular element
void Remove( const T& search );
void Remove( int i );
- // Allows methods to set a context to be used with the less function..
+ /// Allows methods to set a context to be used with the less function..
void SetLessContext( void *pCtx );
- // Note that you can only use this index until sorting is redone!!!
+ /// A version of insertion that will produce an un-ordered list.
+ /// Note that you can only use this index until sorting is redone with RedoSort!!!
int InsertNoSort( const T& src );
void RedoSort( bool bForceSort = false );
+ /// Use this to insert at a specific insertion point; using FindLessOrEqual
+ /// is required for use this this. This will test that what you've inserted
+ /// produces a correctly ordered list.
+ int InsertAfter( int nElemIndex, const T &src );
+
+ /// finds a particular element using a linear search. Useful when used
+ /// in between calls to InsertNoSort and RedoSort
+ template< typename TKey >
+ int FindUnsorted( const TKey &src ) const;
+
protected:
// No copy constructor
CUtlSortVector( const CUtlSortVector<T, LessFunc> & );
@@ -79,10 +97,9 @@ protected:
int AddToTail();
int InsertBefore( int elem );
int InsertAfter( int elem );
+ int InsertBefore( int elem, const T& src );
int AddToHead( const T& src );
int AddToTail( const T& src );
- int InsertBefore( int elem, const T& src );
- int InsertAfter( int elem, const T& src );
int AddMultipleToHead( int num );
int AddMultipleToTail( int num, const T *pToCopy=NULL );
int InsertMultipleBefore( int elem, int num, const T *pToCopy=NULL );
@@ -121,6 +138,10 @@ protected:
bool m_bNeedsSort;
private:
+private:
+ template< typename TKey >
+ int FindLessOrEqual( const TKey& search, bool *pFound ) const;
+
void QuickSort( LessFunc& less, int X, int I );
};
@@ -176,6 +197,43 @@ int CUtlSortVector<T, LessFunc, BaseVector>::InsertNoSort( const T& src )
return lastElement;
}
+/// inserts (copy constructs) an element in sorted order into the list if it isn't already in the list
+template <class T, class LessFunc, class BaseVector>
+int CUtlSortVector<T, LessFunc, BaseVector>::InsertIfNotFound( const T& src )
+{
+ AssertFatal( !m_bNeedsSort );
+ bool bFound;
+ int pos = FindLessOrEqual( src, &bFound );
+ if ( bFound )
+ return pos;
+
+ ++pos;
+ this->GrowVector();
+ this->ShiftElementsRight(pos);
+ CopyConstruct<T>( &this->Element(pos), src );
+ return pos;
+}
+
+template <class T, class LessFunc, class BaseVector>
+int CUtlSortVector<T, LessFunc, BaseVector>::InsertAfter( int nIndex, const T &src )
+{
+ int nInsertedIndex = this->BaseClass::InsertAfter( nIndex, src );
+
+#ifdef DEBUG
+ LessFunc less;
+ if ( nInsertedIndex > 0 )
+ {
+ Assert( less.Less( this->Element(nInsertedIndex-1), src, m_pLessContext ) );
+ }
+ if ( nInsertedIndex < BaseClass::Count()-1 )
+ {
+ Assert( less.Less( src, this->Element(nInsertedIndex+1), m_pLessContext ) );
+ }
+#endif
+ return nInsertedIndex;
+}
+
+
template <class T, class LessFunc, class BaseVector>
void CUtlSortVector<T, LessFunc, BaseVector>::QuickSort( LessFunc& less, int nLower, int nUpper )
{
@@ -218,7 +276,8 @@ void CUtlSortVector<T, LessFunc, BaseVector>::RedoSort( bool bForceSort /*= fals
// finds a particular element
//-----------------------------------------------------------------------------
template <class T, class LessFunc, class BaseVector>
-int CUtlSortVector<T, LessFunc, BaseVector>::Find( const T& src ) const
+template < typename TKey >
+int CUtlSortVector<T, LessFunc, BaseVector>::Find( const TKey& src ) const
{
AssertFatal( !m_bNeedsSort );
@@ -246,10 +305,33 @@ int CUtlSortVector<T, LessFunc, BaseVector>::Find( const T& src ) const
//-----------------------------------------------------------------------------
+// finds a particular element using a linear search. Useful when used
+// in between calls to InsertNoSort and RedoSort
+//-----------------------------------------------------------------------------
+template< class T, class LessFunc, class BaseVector >
+template < typename TKey >
+int CUtlSortVector<T, LessFunc, BaseVector>::FindUnsorted( const TKey &src ) const
+{
+ LessFunc less;
+ int nCount = this->Count();
+ for ( int i = 0; i < nCount; ++i )
+ {
+ if ( less.Less( this->Element(i), src, m_pLessContext ) )
+ continue;
+ if ( less.Less( src, this->Element(i), m_pLessContext ) )
+ continue;
+ return i;
+ }
+ return -1;
+}
+
+
+//-----------------------------------------------------------------------------
// finds a particular element
//-----------------------------------------------------------------------------
template <class T, class LessFunc, class BaseVector>
-int CUtlSortVector<T, LessFunc, BaseVector>::FindLessOrEqual( const T& src ) const
+template < typename TKey >
+int CUtlSortVector<T, LessFunc, BaseVector>::FindLessOrEqual( const TKey& src, bool *pFound ) const
{
AssertFatal( !m_bNeedsSort );
@@ -268,14 +350,26 @@ int CUtlSortVector<T, LessFunc, BaseVector>::FindLessOrEqual( const T& src ) con
}
else
{
+ *pFound = true;
return mid;
}
}
+
+ *pFound = false;
return end;
}
template <class T, class LessFunc, class BaseVector>
-int CUtlSortVector<T, LessFunc, BaseVector>::FindLess( const T& src ) const
+template < typename TKey >
+int CUtlSortVector<T, LessFunc, BaseVector>::FindLessOrEqual( const TKey& src ) const
+{
+ bool bFound;
+ return FindLessOrEqual( src, &bFound );
+}
+
+template <class T, class LessFunc, class BaseVector>
+template < typename TKey >
+int CUtlSortVector<T, LessFunc, BaseVector>::FindLess( const TKey& src ) const
{
AssertFatal( !m_bNeedsSort );