Ignore:
Timestamp:
Jul 23, 2013, 8:14:41 AM (8 years ago)
Author:
sam
Message:

base: Array::Remove(int) now accepts a negative index to remove elements
from the end. Also added Array::RemoveSwap() for faster removes at the
expense of element ordering.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/lol/base/array.h

    r2780 r2809  
    188188    void Remove(int pos, int todelete = 1)
    189189    {
    190         ASSERT(pos >= 0);
    191190        ASSERT(todelete >= 0);
     191        ASSERT(pos - todelete >= -m_count - 1);
    192192        ASSERT(pos + todelete <= m_count);
     193        if (pos < 0)
     194            pos = m_count + pos;
     195
    193196        for (int i = pos; i + todelete < m_count; i++)
    194197            m_data[i] = m_data[i + todelete];
    195198        for (int i = m_count - todelete; i < m_count; i++)
    196199            m_data[i].~Element();
     200        m_count -= todelete;
     201    }
     202
     203    void RemoveSwap(int pos, int todelete = 1)
     204    {
     205        ASSERT(todelete >= 0);
     206        ASSERT(pos - todelete >= -m_count - 1);
     207        ASSERT(pos + todelete <= m_count);
     208        if (pos < 0)
     209            pos = m_count + pos;
     210
     211        for (int i = 0; i < todelete; i++)
     212        {
     213            if (pos + i < m_count - 1 - i)
     214                m_data[pos + i] = m_data[m_count - 1 - i];
     215            m_data[m_count - 1 - i].~Element();
     216        }
    197217        m_count -= todelete;
    198218    }
Note: See TracChangeset for help on using the changeset viewer.