vector.h 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. // Copyright 2010 Google Inc. All Rights Reserved.
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. //
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. //
  15. // Author: [email protected] (Jonathan Tang)
  16. #ifndef GUMBO_VECTOR_H_
  17. #define GUMBO_VECTOR_H_
  18. #include "gumbo.h"
  19. #ifdef __cplusplus
  20. extern "C" {
  21. #endif
  22. // Forward declaration since it's passed into some of the functions in this
  23. // header.
  24. struct GumboInternalParser;
  25. // Initializes a new GumboVector with the specified initial capacity.
  26. void gumbo_vector_init(struct GumboInternalParser* parser,
  27. size_t initial_capacity, GumboVector* vector);
  28. // Frees the memory used by an GumboVector. Does not free the contained
  29. // pointers.
  30. void gumbo_vector_destroy(
  31. struct GumboInternalParser* parser, GumboVector* vector);
  32. // Adds a new element to an GumboVector.
  33. void gumbo_vector_add(
  34. struct GumboInternalParser* parser, void* element, GumboVector* vector);
  35. // Removes and returns the element most recently added to the GumboVector.
  36. // Ownership is transferred to caller. Capacity is unchanged. If the vector is
  37. // empty, NULL is returned.
  38. void* gumbo_vector_pop(struct GumboInternalParser* parser, GumboVector* vector);
  39. // Inserts an element at a specific index. This is potentially O(N) time, but
  40. // is necessary for some of the spec's behavior.
  41. void gumbo_vector_insert_at(struct GumboInternalParser* parser, void* element,
  42. unsigned int index, GumboVector* vector);
  43. // Removes an element from the vector, or does nothing if the element is not in
  44. // the vector.
  45. void gumbo_vector_remove(
  46. struct GumboInternalParser* parser, void* element, GumboVector* vector);
  47. // Removes and returns an element at a specific index. Note that this is
  48. // potentially O(N) time and should be used sparingly.
  49. void* gumbo_vector_remove_at(struct GumboInternalParser* parser,
  50. unsigned int index, GumboVector* vector);
  51. #ifdef __cplusplus
  52. }
  53. #endif
  54. #endif // GUMBO_VECTOR_H_