CoreFW  Check-in [13e46a72ba]

Overview
Comment:New array functions.

* cfw_array_contains()
* cfw_array_contains_ptr()
* cfw_array_find()
* cfw_array_find_ptr()

Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: 13e46a72baec66bba1a5c92d9b8d08d197d3b3d01c9811eef1bd6b6216a0ffd0
User & Date: js on 2012-04-08 18:45:41
Other Links: manifest | tags
Context
2012-04-08
19:02
Install includes. check-in: 526bfbdcdc user: js tags: trunk
18:45
New array functions. check-in: 13e46a72ba user: js tags: trunk
18:12
Add .gitignore. check-in: 97a82f7d9b user: js tags: trunk
Changes

Modified src/cfwarray.c from [8f48f16d9c] to [58791b4765].

21
22
23
24
25
26
27

28
29
30
31
32
33
34
 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 * POSSIBILITY OF SUCH DAMAGE.
 */

#include <stdlib.h>


#include "cfwobject.h"
#include "cfwarray.h"

struct CFWArray {
	CFWObject obj;
	void **data;







>







21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 * POSSIBILITY OF SUCH DAMAGE.
 */

#include <stdlib.h>
#include <stdint.h>

#include "cfwobject.h"
#include "cfwarray.h"

struct CFWArray {
	CFWObject obj;
	void **data;
198
199
200
201
202
203
204
















































205
206
207
208
209
210
211
212
213
214
	cfw_unref(last);

	array->data = new;
	array->size--;

	return true;
}

















































static CFWClass class = {
	.name = "CFWArray",
	.size = sizeof(CFWArray),
	.ctor = ctor,
	.dtor = dtor,
	.equal = equal,
	.copy = copy
};
CFWClass *cfw_array = &class;







>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>










199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
	cfw_unref(last);

	array->data = new;
	array->size--;

	return true;
}

bool
cfw_array_contains(CFWArray *array, void *ptr)
{
	size_t i;

	for (i = 0; i < array->size; i++)
		if (cfw_equal(array->data[i], ptr))
			return true;

	return false;
}

bool
cfw_array_contains_ptr(CFWArray *array, void *ptr)
{
	size_t i;

	for (i = 0; i < array->size; i++)
		if (array->data[i] == ptr)
			return true;

	return false;
}

size_t
cfw_array_find(CFWArray *array, void *ptr)
{
	size_t i;

	for (i = 0; i < array->size; i++)
		if (cfw_equal(array->data[i], ptr))
			return i;

	return SIZE_MAX;
}

size_t
cfw_array_find_ptr(CFWArray *array, void *ptr)
{
	size_t i;

	for (i = 0; i < array->size; i++)
		if (array->data[i] == ptr)
			return i;

	return SIZE_MAX;
}

static CFWClass class = {
	.name = "CFWArray",
	.size = sizeof(CFWArray),
	.ctor = ctor,
	.dtor = dtor,
	.equal = equal,
	.copy = copy
};
CFWClass *cfw_array = &class;

Modified src/cfwarray.h from [f99eaff291] to [34955eb873].

33
34
35
36
37
38
39




40
41
extern CFWClass *cfw_array;
extern size_t cfw_array_size(CFWArray*);
extern void* cfw_array_get(CFWArray*, size_t);
extern bool cfw_array_set(CFWArray*, size_t, void*);
extern bool cfw_array_push(CFWArray*, void*);
extern void* cfw_array_last(CFWArray*);
extern bool cfw_array_pop(CFWArray*);





#endif







>
>
>
>


33
34
35
36
37
38
39
40
41
42
43
44
45
extern CFWClass *cfw_array;
extern size_t cfw_array_size(CFWArray*);
extern void* cfw_array_get(CFWArray*, size_t);
extern bool cfw_array_set(CFWArray*, size_t, void*);
extern bool cfw_array_push(CFWArray*, void*);
extern void* cfw_array_last(CFWArray*);
extern bool cfw_array_pop(CFWArray*);
extern bool cfw_array_contains(CFWArray*, void*);
extern bool cfw_array_contains_ptr(CFWArray*, void*);
extern size_t cfw_array_find(CFWArray*, void*);
extern size_t cfw_array_find_ptr(CFWArray*, void*);

#endif