Cogs.Core
vector.h
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: jdtang@google.com (Jonathan Tang)
16
17#ifndef GUMBO_VECTOR_H_
18#define GUMBO_VECTOR_H_
19
20#include "gumbo.h"
21
22#ifdef __cplusplus
23extern "C" {
24#endif
25
26// Forward declaration since it's passed into some of the functions in this
27// header.
29
30// Initializes a new GumboVector with the specified initial capacity.
31void gumbo_vector_init(struct GumboInternalParser* parser,
32 size_t initial_capacity, GumboVector* vector);
33
34// Frees the memory used by an GumboVector. Does not free the contained
35// pointers.
36void gumbo_vector_destroy(
37 struct GumboInternalParser* parser, GumboVector* vector);
38
39// Adds a new element to an GumboVector.
40void gumbo_vector_add(
41 struct GumboInternalParser* parser, void* element, GumboVector* vector);
42
43// Removes and returns the element most recently added to the GumboVector.
44// Ownership is transferred to caller. Capacity is unchanged. If the vector is
45// empty, NULL is returned.
46void* gumbo_vector_pop(struct GumboInternalParser* parser, GumboVector* vector);
47
48// Inserts an element at a specific index. This is potentially O(N) time, but
49// is necessary for some of the spec's behavior.
50void gumbo_vector_insert_at(struct GumboInternalParser* parser, void* element,
51 unsigned int index, GumboVector* vector);
52
53// Removes an element from the vector, or does nothing if the element is not in
54// the vector.
55void gumbo_vector_remove(
56 struct GumboInternalParser* parser, void* element, GumboVector* vector);
57
58// Removes and returns an element at a specific index. Note that this is
59// potentially O(N) time and should be used sparingly.
60void* gumbo_vector_remove_at(struct GumboInternalParser* parser,
61 unsigned int index, GumboVector* vector);
62
63#ifdef __cplusplus
64}
65#endif
66
67#endif // GUMBO_VECTOR_H_