* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
- * You should have received a copy of the GNU General Public License
- * along with GNU Zebra; see the file COPYING. If not, write to the Free
- * Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
- * 02111-1307, USA.
+ * You should have received a copy of the GNU General Public License along
+ * with this program; see the file COPYING; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include <zebra.h>
}
}
+void vector_remove(vector v, unsigned int ix)
+{
+ if (ix >= v->active)
+ return;
+
+ int n = (--v->active) - ix;
+
+ memmove(&v->index[ix], &v->index[ix + 1], n * sizeof(void *));
+ v->index[v->active] = NULL;
+}
+
+void vector_compact(vector v)
+{
+ for (unsigned int i = 0; i < vector_active(v); ++i) {
+ if (vector_slot(v, i) == NULL) {
+ vector_remove(v, i);
+ --i;
+ }
+ }
+}
+
void vector_unset_value(vector v, void *val)
{
size_t i;
return count;
}
+
+void vector_to_array(vector v, void ***dest, int *argc)
+{
+ *dest = XCALLOC(MTYPE_TMP, sizeof(void *) * v->active);
+ memcpy(*dest, v->index, sizeof(void *) * v->active);
+ *argc = v->active;
+}
+
+vector array_to_vector(void **src, int argc)
+{
+ vector v = vector_init(VECTOR_MIN_SIZE);
+
+ for (int i = 0; i < argc; i++)
+ vector_set_index(v, i, src[i]);
+ return v;
+}