vector.h 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  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(
  27. struct GumboInternalParser* parser, size_t initial_capacity,
  28. GumboVector* vector);
  29. // Frees the memory used by an GumboVector. Does not free the contained
  30. // pointers.
  31. void gumbo_vector_destroy(
  32. struct GumboInternalParser* parser, GumboVector* vector);
  33. // Adds a new element to an GumboVector.
  34. void gumbo_vector_add(
  35. struct GumboInternalParser* parser, void* element, GumboVector* vector);
  36. // Removes and returns the element most recently added to the GumboVector.
  37. // Ownership is transferred to caller. Capacity is unchanged. If the vector is
  38. // empty, NULL is returned.
  39. void* gumbo_vector_pop(struct GumboInternalParser* parser, GumboVector* vector);
  40. // Inserts an element at a specific index. This is potentially O(N) time, but
  41. // is necessary for some of the spec's behavior.
  42. void gumbo_vector_insert_at(
  43. struct GumboInternalParser* parser, void* element, int index,
  44. GumboVector* vector);
  45. // Removes an element from the vector, or does nothing if the element is not in
  46. // the vector.
  47. void gumbo_vector_remove(
  48. struct GumboInternalParser* parser, void* element, GumboVector* vector);
  49. // Removes and returns an element at a specific index. Note that this is
  50. // potentially O(N) time and should be used sparingly.
  51. void* gumbo_vector_remove_at(
  52. struct GumboInternalParser* parser, int index, GumboVector* vector);
  53. #ifdef __cplusplus
  54. }
  55. #endif
  56. #endif // GUMBO_VECTOR_H_