Exemple #1
0
        public static ListLinkedListNode *Create <T>(int capacity, Allocator allocator) where T : unmanaged
        {
            var answer = (ListLinkedListNode *)UnsafeUtility.Malloc(sizeof(ListLinkedListNode), 4, allocator);

            *answer = new ListLinkedListNode(capacity, sizeof(T), allocator);
            return(answer);
        }
Exemple #2
0
        public void Add <T>(ref T copySource, out ListLinkedListNode *page, out int index, Allocator allocator) where T : unmanaged
        {
            ListLinkedListNode *tryNode;

            if (LastFull == null)
            {
                tryNode = First;
            }
            else
            {
                tryNode = LastFull->Next;
            }
            for (; tryNode != null; tryNode = tryNode->Next)
            {
                if (tryNode->TryAdd(ref copySource, out index))
                {
                    if (tryNode->IsFull)
                    {
                        LastFull = tryNode;
                    }
                    page = tryNode;
                    return;
                }
                UnityEngine.Debug.Log("LAST FULL RENEW");
                LastFull = tryNode;
            }
            page  = ListLinkedListNode.Create <T>(NodeCapacity, allocator);
            index = 0;
            page->GetRef <T>(0) = copySource;
            page->Length        = 1;
            for (tryNode = LastFull; IntPtr.Zero != Interlocked.CompareExchange(ref tryNode->NextNodePtr, new IntPtr(page), IntPtr.Zero); tryNode = tryNode->Next)
            {
                ;
            }
        }
Exemple #3
0
 public ASTTypePageIndexPairList(int capacity, Allocator allocator)
 {
     this = default;
     if (capacity == 0)
     {
         return;
     }
     Node = new ListLinkedListNode(capacity, sizeof(ASTTypePageIndexPair), allocator);
 }
Exemple #4
0
 public ListLinkedList(int capacity, int size, Allocator allocator)
 {
     if (capacity < 1)
     {
         throw new ArgumentOutOfRangeException(capacity.ToString() + " must be greater than 0");
     }
     First = (ListLinkedListNode *)UnsafeUtility.Malloc(sizeof(ListLinkedListNode), 4, allocator);
     *First = new ListLinkedListNode(capacity, size, allocator);
     NodeCapacity = capacity;
     LastFull     = null;
 }
Exemple #5
0
        public void AddRange <T>(T *copySource, int length, out ListLinkedListNode *page, out int start, Allocator allocator) where T : unmanaged
        {
            ListLinkedListNode *tryNode;

            if (LastFull == null)
            {
                tryNode = First;
            }
            else if (LastFull->NextNodePtr == IntPtr.Zero)
            {
                tryNode = LastFull;
                goto ADDNEWPAGE;
            }
            else
            {
                tryNode = LastFull->Next;
            }
            if (length > NodeCapacity)
            {
                NodeCapacity = length;
                goto ADDNEWPAGE;
            }
            while (true)
            {
                if (tryNode->TryAdd(copySource, length, out start))
                {
                    if (tryNode->IsFull && LastFull->Next == tryNode)
                    {
                        LastFull = tryNode;
                    }
                    page = tryNode;
                    return;
                }
                if (tryNode->NextNodePtr == IntPtr.Zero)
                {
                    goto ADDNEWPAGE;
                }
                tryNode = tryNode->Next;
            }
ADDNEWPAGE:
            page  = ListLinkedListNode.Create <T>(NodeCapacity, allocator);
            start = 0;
            UnsafeUtility.MemCpy(page->Values, copySource, sizeof(T) * length);
            while (IntPtr.Zero != Interlocked.CompareExchange(ref tryNode->NextNodePtr, new IntPtr(page), IntPtr.Zero))
            {
                tryNode = tryNode->Next;
            }
        }
Exemple #6
0
 public IdentifierNumberPairList(int capacity, Allocator allocator)
 {
     this = default;
     Node = new ListLinkedListNode(capacity, sizeof(IdentifierNumberPair), allocator);
 }