Beispiel #1
0
    // Takes an index and insert it into arr
    private void SearchAndSet(int i, int?v)
    {
        int found = BinarySearchAlgorithm(i, 0, sizecur);

        if (found >= 0 && arr[found].index == i)
        {
            arr[found].value = (int)v;
        }
        else
        {
            // If did not find the value, insert the new value
            found = (found + 1) * -1;
            if (sizecur == sizemax)
            {
                // If the array is full, create a new array
                sizemax = sizemax << 1;
                arrelement[] temp = new arrelement[sizemax];
                for (int x = 0; x < sizecur; x++)
                {
                    temp[x] = arr[x];
                }
                arr = temp;
            }

            for (int x = sizemax - 1; x > found; x--)
            {
                arr[x] = arr[x - 1];
            }
            arr[found] = new arrelement(i, (int)v);
            sizecur++;
        }
    }
Beispiel #2
0
    public arrelement[] GetAllValuesAndReset()
    {
        // Lock to make sure every value has been inserted
        Program.MutexLock(mutexlock);
        arrelement[] temp = new arrelement[sizecur];
        for (int i = 0; i < sizecur; i++)
        {
            temp[i] = arr[i];
        }

        ResetArray();

        // Unlocking the lock when the reseting is done
        Program.MutexUnlock(mutexlock);

        return(temp);
    }