1
0
Fork 0
mirror of https://github.com/zeldaret/oot.git synced 2024-11-14 13:30:47 +00:00
oot/tools/fado/lib/vc_vector
Dragorn421 d4a6b21d46
git subrepo pull (merge) tools/fado (#1501)
subrepo:
  subdir:   "tools/fado"
  merged:   "8d896ee97"
upstream:
  origin:   "git@github.com:EllipticEllipsis/fado.git"
  branch:   "master"
  commit:   "8d896ee97"
git-subrepo:
  version:  "0.4.5"
  origin:   "git@github.com:ingydotnet/git-subrepo.git"
  commit:   "dbb99be"
2023-02-26 14:04:00 -05:00
..
.gitrepo New relocation-generating program (#1016) 2022-02-06 14:40:26 -05:00
.travis.yml New relocation-generating program (#1016) 2022-02-06 14:40:26 -05:00
LICENSE.md New relocation-generating program (#1016) 2022-02-06 14:40:26 -05:00
Makefile New relocation-generating program (#1016) 2022-02-06 14:40:26 -05:00
README.md New relocation-generating program (#1016) 2022-02-06 14:40:26 -05:00
vc_vector.c git subrepo pull (merge) tools/fado (#1501) 2023-02-26 14:04:00 -05:00
vc_vector.h git subrepo pull (merge) tools/fado (#1501) 2023-02-26 14:04:00 -05:00
vc_vector_test.c New relocation-generating program (#1016) 2022-02-06 14:40:26 -05:00
vc_vector_test.h New relocation-generating program (#1016) 2022-02-06 14:40:26 -05:00

vc_vector

Fast simple C vector implementation

Build Status: make && make test

Usage

Basic

#include "vc_vector.h"

int main() {
  // Creates an empty vector with the default reserved size
  // and without custom deleter. Vector will contain 'int'
  vc_vector* v = vc_vector_create(0, sizeof(int), NULL);
  if (!v) {
    return 1;
  }

  const int count = 10;
  for (int i = 0; i < count; ++i) {
    // The function takes a pointer to the elements,
    // but the vector will make a copy of the element
    vc_vector_push_back(v, &i);
  }

  // Print each vector element
  for (void* i = vc_vector_begin(v);
             i != vc_vector_end(v);
             i = vc_vector_next(v, i)) {
    printf("%u; ", *(int*)i);
  }

  vc_vector_release(v);
  return 0;
}

Advanced

#include "vc_vector.h"

struct Item {
  int val1;
  int val2;
};

int main() {
  const int n = 10;

  // Creates an empty vector with the reserved size for the 'n' elements
  // and with custom deleter 'free'. Vector will contain pointers to 'Item'
  vc_vector* v = vc_vector_create(n, sizeof(struct Node*), free);
  if (!v) {
    return 1;
  }

  struct Item* item = NULL;
  const int count = n + 1;
  // Vector automatically increases the reserved size when 'n + 1' will be added
  for (int i = 0; i < count; ++i) {
    // Creating item
    item = malloc(sizeof(struct Item));
    if (!item) {
      continue;
    }

    item->val1 = i;
    item->val2 = 0;

    // Pushing to the end of the vector
    if (!vc_vector_push_back(v, item)) {
      // If the item was not pushed, you have to delete it
      free(item);
    }
  }

  // ...

  // Calls custom deleter 'free' for all items
  // and releases the vector
  vc_vector_release(v);
  return 0;
}

Projects that use vc_vector

kraken.io

License

MIT License