Package cds.moc

Class LongArray

  • All Implemented Interfaces:
    java.lang.Cloneable, java.lang.Iterable<java.lang.Long>

    public final class LongArray
    extends Array
    Fast array of longs
    • Constructor Summary

      Constructors 
      Constructor Description
      LongArray​(int bloc)
      Create a free array of longs
      LongArray​(long[] v)
      Create an array of longs initializing with v[]
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      boolean add​(long v, boolean testUnicity)
      Add a long.
      Array clone()
      Deep copy
      boolean delete​(long v)
      Delete the first value equals to v kept the array sorted if required
      boolean delete​(long v1, long v2)
      Delete the all values between v1 and v2 (inclusive) kept the array sorted if required
      boolean deleteBrothers​(long me)
      Delete three other brothers only if all of them are already present (apart me)
      boolean equals​(Array a)
      Equality test
      int find​(long v)
      Return the index of the first value v.
      long get​(int i)
      Provide the element i
      long getMem()
      Size of the array in bytes
      int getSizeCompressed()
      Size of the array in compressed mode => consecutive values are memorized as range (2 values)
      boolean intersectRange​(long vStart, long vEnd)
      Return true if at least one value of the range [vStart..vEnd] (included) is found in the array
      long[] seeArray()
      Provide the java reference on the array (real size is provided by getSize() and not by .length)
      void set​(int i, long v)
      set the element i
      void sort()
      Sort the array (only if required)
      void trim()
      Remove the reservation room in the array
      • Methods inherited from class java.lang.Object

        equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
      • Methods inherited from interface java.lang.Iterable

        forEach, spliterator
    • Constructor Detail

      • LongArray

        public LongArray​(int bloc)
        Create a free array of longs
      • LongArray

        public LongArray​(long[] v)
        Create an array of longs initializing with v[]
        Parameters:
        v - initial values of the array
    • Method Detail

      • clone

        public Array clone()
        Deep copy
        Specified by:
        clone in class Array
      • equals

        public boolean equals​(Array a)
        Equality test
        Specified by:
        equals in class Array
      • seeArray

        public long[] seeArray()
        Provide the java reference on the array (real size is provided by getSize() and not by .length)
        Returns:
        array of longs
      • get

        public long get​(int i)
        Description copied from class: Array
        Provide the element i
        Specified by:
        get in class Array
      • set

        public void set​(int i,
                        long v)
        Description copied from class: Array
        set the element i
        Specified by:
        set in class Array
      • getMem

        public long getMem()
        Size of the array in bytes
        Specified by:
        getMem in class Array
      • getSizeCompressed

        public int getSizeCompressed()
        Size of the array in compressed mode => consecutive values are memorized as range (2 values)
        Specified by:
        getSizeCompressed in class Array
        Returns:
        Number of values
      • add

        public boolean add​(long v,
                           boolean testUnicity)
        Add a long. the array will be automatically extended if necessary
        Specified by:
        add in class Array
        Parameters:
        v - value to add
        testUnicity - true for avoiding redundancy (slower)
        Returns:
        true if the value has been added
      • delete

        public boolean delete​(long v)
        Delete the first value equals to v kept the array sorted if required
        Specified by:
        delete in class Array
        Parameters:
        v - the value to remove
        Returns:
        true if the value has been removed
      • delete

        public boolean delete​(long v1,
                              long v2)
        Delete the all values between v1 and v2 (inclusive) kept the array sorted if required
        Specified by:
        delete in class Array
        Parameters:
        v1 - the low range value
        v2 - the high range value
        Returns:
        true if at least one value has been removed
      • deleteBrothers

        public boolean deleteBrothers​(long me)
        Delete three other brothers only if all of them are already present (apart me)
        Specified by:
        deleteBrothers in class Array
        Returns:
        false if not found
      • find

        public int find​(long v)
        Return the index of the first value v. -1 if not found. If the arrays is sorted, proceeds by bsearch (see bsearch doc)
        Specified by:
        find in class Array
        Parameters:
        v - Value to find
        Returns:
        index of the value, otherwise negative index
      • intersectRange

        public boolean intersectRange​(long vStart,
                                      long vEnd)
        Return true if at least one value of the range [vStart..vEnd] (included) is found in the array
        Specified by:
        intersectRange in class Array
        Parameters:
        vStart - range starting value
        vEnd - range ending value
        Returns:
        true in case of success
      • sort

        public void sort()
        Sort the array (only if required)
        Specified by:
        sort in class Array
      • trim

        public void trim()
        Remove the reservation room in the array
        Specified by:
        trim in class Array