vector: Add REMOVE, ADD_SORTED and RESET macros

Based on feedback from Corey Farrell and Y Ateya, a few new
macros have been added...

AST_VECTOR_REMOVE which takes a parameter to indicate if
order should be preserved.

AST_VECTOR_ADD_SORTED which adds an element to
a sorted vector.

AST_VECTOR_RESET which cleans all elements from the vector
leaving the storage intact.

Change-Id: I41d32dbdf7137e0557134efeff9f9f1064b58d14
This commit is contained in:
George Joseph
2015-05-09 15:58:46 -06:00
parent 4da2934592
commit 87d8b36755
2 changed files with 103 additions and 22 deletions

View File

@@ -63,7 +63,9 @@ AST_TEST_DEFINE(basic_ops)
char *CCC = "CCC";
char *YYY = "YYY";
char *ZZZ = "ZZZ";
char CCC2[4];
strcpy(CCC2, "CCC");
switch (cmd) {
case TEST_INIT:
info->name = "basic";
@@ -202,6 +204,29 @@ AST_TEST_DEFINE(basic_ops)
ast_test_validate_cleanup(test, AST_VECTOR_GET(&sv1, 0) == CCC, rc, cleanup);
ast_test_validate_cleanup(test, cleanup_count == 1, rc, cleanup);
/* Test INSERT_SORTED */
AST_VECTOR_FREE(&sv1);
ast_test_validate(test, AST_VECTOR_INIT(&sv1, 0) == 0);
ast_test_validate_cleanup(test, AST_VECTOR_ADD_SORTED(&sv1, BBB, strcmp) == 0, rc, cleanup);
ast_test_validate_cleanup(test, AST_VECTOR_ADD_SORTED(&sv1, ZZZ, strcmp) == 0, rc, cleanup);
ast_test_validate_cleanup(test, AST_VECTOR_ADD_SORTED(&sv1, CCC, strcmp) == 0, rc, cleanup);
ast_test_validate_cleanup(test, AST_VECTOR_ADD_SORTED(&sv1, AAA, strcmp) == 0, rc, cleanup);
ast_test_validate_cleanup(test, AST_VECTOR_ADD_SORTED(&sv1, CCC2, strcmp) == 0, rc, cleanup);
ast_test_validate_cleanup(test, AST_VECTOR_GET(&sv1, 0) == AAA, rc, cleanup);
ast_test_validate_cleanup(test, AST_VECTOR_GET(&sv1, 1) == BBB, rc, cleanup);
ast_test_validate_cleanup(test, AST_VECTOR_GET(&sv1, 2) == CCC, rc, cleanup);
ast_test_validate_cleanup(test, AST_VECTOR_GET(&sv1, 3) == CCC2, rc, cleanup);
ast_test_validate_cleanup(test, AST_VECTOR_GET(&sv1, 4) == ZZZ, rc, cleanup);
cleanup_count = 0;
AST_VECTOR_RESET(&sv1, cleanup);
ast_test_validate_cleanup(test, AST_VECTOR_SIZE(&sv1) == 0, rc, cleanup);
ast_test_validate_cleanup(test, sv1.max >= 5, rc, cleanup);
ast_test_validate_cleanup(test, sv1.elems != NULL, rc, cleanup);
ast_test_validate_cleanup(test, cleanup_count == 5, rc, cleanup);
cleanup:
AST_VECTOR_FREE(&sv1);
return rc;
@@ -218,13 +243,13 @@ AST_TEST_DEFINE(basic_ops_integer)
int rc = AST_TEST_PASS;
int AAA = 1;
int BBB = 2;
int CCC = 3;
int BBB = 3;
int CCC = 5;
int ZZZ = 26;
switch (cmd) {
case TEST_INIT:
info->name = "basic integer";
info->name = "basic_integer";
info->category = "/main/vector/";
info->summary = "Test integer vector basic ops";
info->description = "Test integer vector basic ops";