src/core/smallvec_type.hpp
changeset 11049 f8bbc9635251
parent 11019 9c818b06c54d
equal deleted inserted replaced
11047:f4e7290c23b9 11049:f8bbc9635251
    34 	}
    34 	}
    35 
    35 
    36 	/**
    36 	/**
    37 	 * Remove all items from the list.
    37 	 * Remove all items from the list.
    38 	 */
    38 	 */
    39 	void Clear()
    39 	FORCEINLINE void Clear()
    40 	{
    40 	{
    41 		/* In fact we just reset the item counter avoiding the need to
    41 		/* In fact we just reset the item counter avoiding the need to
    42 		 * probably reallocate the same amount of memory the list was
    42 		 * probably reallocate the same amount of memory the list was
    43 		 * previously using. */
    43 		 * previously using. */
    44 		this->items = 0;
    44 		this->items = 0;
    45 	}
    45 	}
    46 
    46 
    47 	/**
    47 	/**
    48 	 * Compact the list down to the smallest block size boundary.
    48 	 * Compact the list down to the smallest block size boundary.
    49 	 */
    49 	 */
    50 	void Compact()
    50 	FORCEINLINE void Compact()
    51 	{
    51 	{
    52 		uint capacity = Align(this->items, S);
    52 		uint capacity = Align(this->items, S);
    53 		if (capacity >= this->capacity) return;
    53 		if (capacity >= this->capacity) return;
    54 
    54 
    55 		this->capacity = capacity;
    55 		this->capacity = capacity;
    57 	}
    57 	}
    58 
    58 
    59 	/**
    59 	/**
    60 	 * Append an item and return it.
    60 	 * Append an item and return it.
    61 	 */
    61 	 */
    62 	T *Append()
    62 	FORCEINLINE T *Append()
    63 	{
    63 	{
    64 		if (this->items == this->capacity) {
    64 		if (this->items == this->capacity) {
    65 			this->capacity += S;
    65 			this->capacity += S;
    66 			this->data = ReallocT(this->data, this->capacity);
    66 			this->data = ReallocT(this->data, this->capacity);
    67 		}
    67 		}
    70 	}
    70 	}
    71 
    71 
    72 	/**
    72 	/**
    73 	 * Get the number of items in the list.
    73 	 * Get the number of items in the list.
    74 	 */
    74 	 */
    75 	uint Length() const
    75 	FORCEINLINE uint Length() const
    76 	{
    76 	{
    77 		return this->items;
    77 		return this->items;
    78 	}
    78 	}
    79 
    79 
    80 	/**
    80 	/**
    81 	 * Get the pointer to the first item (const)
    81 	 * Get the pointer to the first item (const)
    82 	 *
    82 	 *
    83 	 * @return the pointer to the first item
    83 	 * @return the pointer to the first item
    84 	 */
    84 	 */
    85 	const T *Begin() const
    85 	FORCEINLINE const T *Begin() const
    86 	{
    86 	{
    87 		return this->data;
    87 		return this->data;
    88 	}
    88 	}
    89 
    89 
    90 	/**
    90 	/**
    91 	 * Get the pointer to the first item
    91 	 * Get the pointer to the first item
    92 	 *
    92 	 *
    93 	 * @return the pointer to the first item
    93 	 * @return the pointer to the first item
    94 	 */
    94 	 */
    95 	T *Begin()
    95 	FORCEINLINE T *Begin()
    96 	{
    96 	{
    97 		return this->data;
    97 		return this->data;
    98 	}
    98 	}
    99 
    99 
   100 	/**
   100 	/**
   101 	 * Get the pointer behind the last valid item (const)
   101 	 * Get the pointer behind the last valid item (const)
   102 	 *
   102 	 *
   103 	 * @return the pointer behind the last valid item
   103 	 * @return the pointer behind the last valid item
   104 	 */
   104 	 */
   105 	const T *End() const
   105 	FORCEINLINE const T *End() const
   106 	{
   106 	{
   107 		return &this->data[this->items];
   107 		return &this->data[this->items];
   108 	}
   108 	}
   109 
   109 
   110 	/**
   110 	/**
   111 	 * Get the pointer behind the last valid item
   111 	 * Get the pointer behind the last valid item
   112 	 *
   112 	 *
   113 	 * @return the pointer behind the last valid item
   113 	 * @return the pointer behind the last valid item
   114 	 */
   114 	 */
   115 	T *End()
   115 	FORCEINLINE T *End()
   116 	{
   116 	{
   117 		return &this->data[this->items];
   117 		return &this->data[this->items];
   118 	}
   118 	}
   119 
   119 
   120 	/**
   120 	/**
   121 	 * Get the pointer to item "number" (const)
   121 	 * Get the pointer to item "number" (const)
   122 	 *
   122 	 *
   123 	 * @param index the position of the item
   123 	 * @param index the position of the item
   124 	 * @return the pointer to the item
   124 	 * @return the pointer to the item
   125 	 */
   125 	 */
   126 	const T *Get(uint index) const
   126 	FORCEINLINE const T *Get(uint index) const
   127 	{
   127 	{
   128 		return &this->data[index];
   128 		return &this->data[index];
   129 	}
   129 	}
   130 
   130 
   131 	/**
   131 	/**
   132 	 * Get the pointer to item "number"
   132 	 * Get the pointer to item "number"
   133 	 *
   133 	 *
   134 	 * @param index the position of the item
   134 	 * @param index the position of the item
   135 	 * @return the pointer to the item
   135 	 * @return the pointer to the item
   136 	 */
   136 	 */
   137 	T *Get(uint index)
   137 	FORCEINLINE T *Get(uint index)
   138 	{
   138 	{
   139 		return &this->data[index];
   139 		return &this->data[index];
   140 	}
   140 	}
   141 
   141 
   142 	/**
   142 	/**
   143 	 * Get item "number" (const)
   143 	 * Get item "number" (const)
   144 	 *
   144 	 *
   145 	 * @param index the positon of the item
   145 	 * @param index the positon of the item
   146 	 * @return the item
   146 	 * @return the item
   147 	 */
   147 	 */
   148 	const T &operator[](uint index) const
   148 	FORCEINLINE const T &operator[](uint index) const
   149 	{
   149 	{
   150 		return this->data[index];
   150 		return this->data[index];
   151 	}
   151 	}
   152 
   152 
   153 	/**
   153 	/**
   154 	 * Get item "number"
   154 	 * Get item "number"
   155 	 *
   155 	 *
   156 	 * @param index the positon of the item
   156 	 * @param index the positon of the item
   157 	 * @return the item
   157 	 * @return the item
   158 	 */
   158 	 */
   159 	T &operator[](uint index)
   159 	FORCEINLINE T &operator[](uint index)
   160 	{
   160 	{
   161 		return this->data[index];
   161 		return this->data[index];
   162 	}
   162 	}
   163 };
   163 };
   164 
   164