Oracle® Fusion Middleware C++ API Reference for Oracle Coherence
12c (12.2.1.3.0)

E80355-01

coherence/util/Arrays.hpp

00001 /*
00002 * Arrays.hpp
00003 *
00004 * Copyright (c) 2000, 2017, Oracle and/or its affiliates. All rights reserved.
00005 *
00006 * Oracle is a registered trademarks of Oracle Corporation and/or its
00007 * affiliates.
00008 *
00009 * This software is the confidential and proprietary information of Oracle
00010 * Corporation. You shall not disclose such confidential and proprietary
00011 * information and shall use it only in accordance with the terms of the
00012 * license agreement you entered into with Oracle.
00013 *
00014 * This notice may not be removed or altered.
00015 */
00016 #ifndef COH_ARRAYS_HPP
00017 #define COH_ARRAYS_HPP
00018 
00019 #include "coherence/lang.ns"
00020 
00021 #include "coherence/util/Comparator.hpp"
00022 #include "coherence/util/List.hpp"
00023 
00024 COH_OPEN_NAMESPACE2(coherence,util)
00025 
00026 
00027 /**
00028 * This class contains various methods for manipulating arrays (such as
00029 * sorting and searching).
00030 *
00031 * @author tb  2008.04.04
00032 */
00033 class COH_EXPORT Arrays
00034     {
00035     // ----- static methods -------------------------------------------------
00036 
00037     public:
00038         /**
00039         * Copies an array from the specified source array, beginning at the
00040         * specified position, to the specified position of the destination
00041         * array.
00042         *
00043         * @param haoSrc      the source array
00044         * @param iSrcStart   starting position in the source array
00045         * @param haoDest     the destination array
00046         * @param iDestStart  starting position in the destination data
00047         * @param cElements   the number of array elements to be copied
00048         * @throws IndexOutOfBoundsException  if copying would cause
00049         *               access of data outside array bounds
00050         */
00051         static void copy(ObjectArray::Handle haoSrc,
00052                 size32_t iSrcStart, ObjectArray::Handle haoDest,
00053                 size32_t iDestStart, size32_t cElements);
00054 
00055         /**
00056          * Reverses the order of the elements in the specified array.
00057          *
00058          * This method runs in linear time.
00059          *
00060          * @param hao  the array whose elements are to be reversed.
00061          *
00062          * since 12.2.1.3
00063          */
00064         static void reverse(ObjectArray::Handle hao);
00065 
00066         /**
00067         * Sorts the specified array of objects according to the order induced
00068         * by the specified comparator.  All elements in the array must be
00069         * mutually comparable by the specified comparator.
00070         *
00071         * This sort is guaranteed to be stable:  equal elements will not be
00072         * reordered as a result of the sort.<p>
00073         *
00074         * @param hao          the array to be sorted
00075         * @param hComparator  the comparator to determine the order of the
00076         *                     array.  A null value indicates that the
00077         *                     elements' natural ordering should be used
00078         * @throws ClassCastException  if the array contains elements that are
00079         *      not mutually comparable
00080         */
00081         static void sort(ObjectArray::Handle hao,
00082                 Comparator::Handle hComparator = NULL);
00083 
00084         /**
00085          * Swaps the elements at the specified positions in the specified array.
00086          * (If the specified positions are equal, invoking this method leaves
00087          * the array unchanged.)
00088          *
00089          * @param hao  the array in which to swap elements.
00090          * @param i    the index of one element to be swapped.
00091          * @param j    the index of the other element to be swapped.
00092          *
00093          * @throws IndexOutOfBoundsException if either <tt>i</tt> or <tt>j</tt>
00094          *         is out of range (i &lt; 0 || i &gt;= hList->length
00095          *         || j &lt; 0 || j &gt;= hList->length).
00096          *
00097          * @since 12.2.1.3
00098          */
00099         static void swap(ObjectArray::Handle hao, size32_t i, size32_t j);
00100 
00101         /**
00102         * Performs a binary search for the specified element in the
00103         * specified sorted array using the Comparator to compare elements.
00104         *
00105         * @param vaoSorted    the sorted Object array to search
00106         * @param vo           the value element to find
00107         * @param vComparator  the Comparator (optional)
00108         *
00109         * @return the non-negative index of the element, or a negative index
00110         *         which is the -index - 1 where the element would be inserted
00111         */
00112         static int32_t binarySearch(ObjectArray::View vaoSorted,
00113                 Object::View vo, Comparator::View vComparator = NULL);
00114 
00115         /**
00116         * Performs a binary search for the specified element in a part of the
00117         * specified sorted array using the Comparator to compare elements.
00118         *
00119         * @param vaoSorted    the sorted Object array to search
00120         * @param iStart       the inclusive start index
00121         * @param iEnd         the exclusive end index
00122         * @param vo           the value element to find
00123         * @param vComparator  the Comparator (optional)
00124         *
00125         * @return the non-negative index of the element, or a negative index
00126         *         which is the -index - 1 where the element would be inserted
00127         */
00128         static int32_t binarySearch(ObjectArray::View vaoSorted,
00129                 size32_t iStart, size32_t iEnd, Object::View vo,
00130                 Comparator::View vComparator = NULL);
00131 
00132         /**
00133         * Returns a fixed-size list backed by the specified array. (Changes
00134         * to the returned list "write through" to the array.) This method
00135         * acts as bridge between array-based and collection-based APIs.
00136         * This method also provides a convenient way to create a fixed-size
00137         * list initialized to contain several elements:
00138         *
00139         * @param vao  the array by which the list will be backed
00140         *
00141         * @return a list view of the specified array
00142         *
00143         * @since Coherence 12.1.2
00144         */
00145         static List::View asList(ObjectArray::View vao);
00146     };
00147 
00148 COH_CLOSE_NAMESPACE2
00149 
00150 #endif // COH_ARRAYS_HPP
Copyright © 2000, 2017, Oracle and/or its affiliates. All rights reserved.