예제 #1
0
        public static int IndexOf <T>(UnsafeList *list, T item) where T : unmanaged, IEquatable <T>
        {
            UDebug.Assert(list != null);
            UDebug.Assert(list->_items.Ptr != null);
            UDebug.Assert(typeof(T).TypeHandle.Value == list->_typeHandle);

            return(UnsafeBuffer.IndexOf(list->_items, item, 0, list->_count));
        }
예제 #2
0
        public static bool Contains <T>(UnsafeRingBuffer *ringbuffer, T item) where T : unmanaged, IEquatable <T>
        {
            UDebug.Assert(ringbuffer != null);
            UDebug.Assert(ringbuffer->_items.Ptr != null);
            UDebug.Assert(typeof(T).TypeHandle.Value == ringbuffer->_typeHandle);

            int count = ringbuffer->_count;
            int head  = ringbuffer->_head;
            int tail  = ringbuffer->_tail;

            if (count == 0)
            {
                return(false);
            }

            if (head < tail)
            {
                return(UnsafeBuffer.IndexOf(ringbuffer->_items, item, head, count) > -1);
            }

            return(UnsafeBuffer.IndexOf(ringbuffer->_items, item, head, ringbuffer->_items.Length - head) > -1 ||
                   UnsafeBuffer.IndexOf(ringbuffer->_items, item, 0, tail) > -1);
        }