uvectr32.h revision ac04d0bbe12b3ef54518635711412f178cb4d16
1ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru/*
2ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru**********************************************************************
3ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru*   Copyright (C) 1999-2006, International Business Machines
4ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru*   Corporation and others.  All Rights Reserved.
5ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru**********************************************************************
6ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru*/
7ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
8ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru//
9ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru//  UVector32 is a class implementing a vector of 32 bit integers.
10ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru//            It is similar to UVector, but holds int32_t values rather than pointers.
11ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru//            Most of the code is unchanged from UVector.
12ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru//
13ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
14ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#ifndef UVECTOR32_H
15ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#define UVECTOR32_H
16ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
17ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#include "unicode/utypes.h"
18ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#include "unicode/uobject.h"
19ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#include "uhash.h"
20ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#include "uassert.h"
21ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
22ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste QueruU_NAMESPACE_BEGIN
23ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
24ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
25ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
26ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru/**
27ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * <p>Ultralightweight C++ implementation of a <tt>void*</tt> vector
28ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * that is (mostly) compatible with java.util.Vector.
29ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru *
30ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * <p>This is a very simple implementation, written to satisfy an
31ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * immediate porting need.  As such, it is not completely fleshed out,
32ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * and it aims for simplicity and conformity.  Nonetheless, it serves
33ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * its purpose (porting code from java that uses java.util.Vector)
34ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * well, and it could be easily made into a more robust vector class.
35ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru *
36ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * <p><b>Design notes</b>
37ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru *
38ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * <p>There is index bounds checking, but little is done about it.  If
39ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * indices are out of bounds, either nothing happens, or zero is
40ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * returned.  We <em>do</em> avoid indexing off into the weeds.
41ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru *
42ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * <p>There is detection of out of memory, but the handling is very
43ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * coarse-grained -- similar to UnicodeString's protocol, but even
44ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * coarser.  The class contains <em>one static flag</em> that is set
45ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * when any call to <tt>new</tt> returns zero.  This allows the caller
46ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * to use several vectors and make just one check at the end to see if
47ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * a memory failure occurred.  This is more efficient than making a
48ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * check after each call on each vector when doing many operations on
49ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * multiple vectors.  The single static flag works best when memory
50ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * failures are infrequent, and when recovery options are limited or
51ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * nonexistent.
52ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru *
53ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * <p><b>To do</b>
54ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru *
55ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * <p>Improve the handling of index out of bounds errors.
56ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru *
57ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * @author Alan Liu
58ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru */
59ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queruclass U_COMMON_API UVector32 : public UObject {
60ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queruprivate:
61ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    int32_t   count;
62ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
63ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    int32_t   capacity;
64ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
65ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    int32_t*  elements;
66ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
67ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Querupublic:
68ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    UVector32(UErrorCode &status);
69ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
70ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    UVector32(int32_t initialCapacity, UErrorCode &status);
71ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
72ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    virtual ~UVector32();
73ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
74ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    /**
75ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru     * Assign this object to another (make this a copy of 'other').
76ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru     * Use the 'assign' function to assign each element.
77ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru     */
78ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    void assign(const UVector32& other, UErrorCode &ec);
79ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
80ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    /**
81ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru     * Compare this vector with another.  They will be considered
82ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru     * equal if they are of the same size and all elements are equal,
83ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru     * as compared using this object's comparer.
84ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru     */
85ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    UBool operator==(const UVector32& other);
86ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
87ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    /**
88ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru     * Equivalent to !operator==()
89ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru     */
90ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    inline UBool operator!=(const UVector32& other);
91ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
92ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    //------------------------------------------------------------
93ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    // java.util.Vector API
94ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    //------------------------------------------------------------
95ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
96ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    void addElement(int32_t elem, UErrorCode &status);
97ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
98ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    void setElementAt(int32_t elem, int32_t index);
99ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
100ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    void insertElementAt(int32_t elem, int32_t index, UErrorCode &status);
101ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
102ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    int32_t elementAti(int32_t index) const;
103ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
104ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    UBool equals(const UVector32 &other) const;
105ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
106ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    int32_t lastElementi(void) const;
107ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
108ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    int32_t indexOf(int32_t elem, int32_t startIndex = 0) const;
109ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
110ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    UBool contains(int32_t elem) const;
111ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
112ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    UBool containsAll(const UVector32& other) const;
113ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
114ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    UBool removeAll(const UVector32& other);
115ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
116ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    UBool retainAll(const UVector32& other);
117ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
118ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    void removeElementAt(int32_t index);
119ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
120ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    void removeAllElements();
121ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
122ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    int32_t size(void) const;
123ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
124ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    UBool isEmpty(void) const;
125ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
126ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    // Inline.  Use this one for speedy size check.
127ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    inline UBool ensureCapacity(int32_t minimumCapacity, UErrorCode &status);
128ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
129ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    // Out-of-line, handles actual growth.  Called by ensureCapacity() when necessary.
130ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    UBool expandCapacity(int32_t minimumCapacity, UErrorCode &status);
131ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
132ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    /**
133ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru     * Change the size of this vector as follows: If newSize is
134ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru     * smaller, then truncate the array, possibly deleting held
135ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru     * elements for i >= newSize.  If newSize is larger, grow the
136ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru     * array, filling in new slows with zero.
137ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru     */
138ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    void setSize(int32_t newSize);
139ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
140ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    //------------------------------------------------------------
141ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    // New API
142ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    //------------------------------------------------------------
143ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
144ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    /**
145ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru     * Returns true if this vector contains none of the elements
146ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru     * of the given vector.
147ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru     * @param other vector to be checked for containment
148ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru     * @return true if the test condition is met
149ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru     */
150ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    UBool containsNone(const UVector32& other) const;
151ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
152ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
153ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    /**
154ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru     * Insert the given integer into this vector at its sorted position.
155ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru     * The current elements are assumed to be sorted already.
156ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru     */
157ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    void sortedInsert(int32_t elem, UErrorCode& ec);
158ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
159ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    /**
160ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru     * Returns a pointer to the internal array holding the vector.
161ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru     */
162ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    int32_t *getBuffer() const;
163ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
164ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    /**
165ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru     * ICU "poor man's RTTI", returns a UClassID for this class.
166ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru     */
167ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    static UClassID U_EXPORT2 getStaticClassID();
168ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
169ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    /**
170ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru     * ICU "poor man's RTTI", returns a UClassID for the actual class.
171ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru     */
172ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    virtual UClassID getDynamicClassID() const;
173ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
174ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queruprivate:
175ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    void _init(int32_t initialCapacity, UErrorCode &status);
176ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
177ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    // Disallow
178ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    UVector32(const UVector32&);
179ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
180ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    // Disallow
181ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    UVector32& operator=(const UVector32&);
182ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
183ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
184ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    //  API Functions for Stack operations.
185ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    //  In the original UVector, these were in a separate derived class, UStack.
186ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    //  Here in UVector32, they are all together.
187ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Querupublic:
188ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    UBool empty(void) const;   // TODO:  redundant, same as empty().  Remove it?
189ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
190ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    int32_t peeki(void) const;
191ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
192ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    int32_t popi(void);
193ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
194ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    int32_t push(int32_t i, UErrorCode &status);
195ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
196ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    int32_t *reserveBlock(int32_t size, UErrorCode &status);
197ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    int32_t *popFrame(int32_t size);
198ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru};
199ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
200ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
201ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru// UVector32 inlines
202ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
203ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queruinline UBool UVector32::ensureCapacity(int32_t minimumCapacity, UErrorCode &status) {
204ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    if (capacity >= minimumCapacity) {
205ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        return TRUE;
206ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    } else {
207ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        return expandCapacity(minimumCapacity, status);
208ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    }
209ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru}
210ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
211ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queruinline int32_t UVector32::elementAti(int32_t index) const {
212ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    return (0 <= index && index < count) ? elements[index] : 0;
213ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru}
214ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
215ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
216ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queruinline void UVector32::addElement(int32_t elem, UErrorCode &status) {
217ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    if (ensureCapacity(count + 1, status)) {
218ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        elements[count] = elem;
219ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        count++;
220ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    }
221ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru}
222ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
223ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queruinline int32_t *UVector32::reserveBlock(int32_t size, UErrorCode &status) {
224ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    ensureCapacity(count+size, status);
225ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    int32_t  *rp = elements+count;
226ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    count += size;
227ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    return rp;
228ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru}
229ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
230ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queruinline int32_t *UVector32::popFrame(int32_t size) {
231ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    U_ASSERT(count >= size);
232ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    count -= size;
233ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    if (count < 0) {
234ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        count = 0;
235ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    }
236ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    return elements+count-size;
237ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru}
238ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
239ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
240ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
241ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queruinline int32_t UVector32::size(void) const {
242ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    return count;
243ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru}
244ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
245ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queruinline UBool UVector32::isEmpty(void) const {
246ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    return count == 0;
247ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru}
248ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
249ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queruinline UBool UVector32::contains(int32_t obj) const {
250ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    return indexOf(obj) >= 0;
251ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru}
252ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
253ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queruinline int32_t UVector32::lastElementi(void) const {
254ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    return elementAti(count-1);
255ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru}
256ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
257ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queruinline UBool UVector32::operator!=(const UVector32& other) {
258ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    return !operator==(other);
259ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru}
260ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
261ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queruinline int32_t *UVector32::getBuffer() const {
262ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    return elements;
263ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru}
264ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
265ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
266ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru// UStack inlines
267ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
268ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queruinline UBool UVector32::empty(void) const {
269ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    return isEmpty();
270ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru}
271ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
272ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queruinline int32_t UVector32::peeki(void) const {
273ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    return lastElementi();
274ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru}
275ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
276ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queruinline int32_t UVector32::push(int32_t i, UErrorCode &status) {
277ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    addElement(i, status);
278ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    return i;
279ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru}
280ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
281ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queruinline int32_t UVector32::popi(void) {
282ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    int32_t result = 0;
283ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    if (count > 0) {
284ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        count--;
285ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        result = elements[count];
286ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    }
287ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    return result;
288ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru}
289ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
290ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste QueruU_NAMESPACE_END
291ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
292ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#endif
293