prometheus-client-mmap 0.7.0.beta42 → 0.7.0.beta43

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: e546160d5f4baf942cd59595ba9f4738f5bb112a
4
- data.tar.gz: d2369f52a14a938fec91c09d372396c031992234
3
+ metadata.gz: 4521825ca75920135fbbaf6fb8e5c96bd0d191ee
4
+ data.tar.gz: '06686cb19e896c65356e2ed44c6398adb69d4a01'
5
5
  SHA512:
6
- metadata.gz: c02fd8414f65779692b0aac43e89f53a87492843bae04891924838320533f495de9977ba2c99c72d34553d937268fa0ee6b5859861f1f13a86a5969c74b4320f
7
- data.tar.gz: e9bf20cc0e44dd7307b429dd088d82702a25073bbd72ff0cc9315d4e2580e7438042b98032c21f7ddb0f668afd6bf42c0018e3f4bd81dfb40c30b79d0ecab9b4
6
+ metadata.gz: 262ea3d30cce8cc62b56c098cb983c0c43a55bad40b6374c7ea72df8c45404e0fc978bd9e0b0498ae512ee9818cd2742f823bf583dbcff02ae1be01e1591063d
7
+ data.tar.gz: 7cd7db57d62f2f9bbf5da3940ce12d6ca849d17e09530a52ca351475a5eea7fbfadeacf65af2793613be20363ebff46696c8248af0019e10bc3b768d3bdd978c
@@ -30,6 +30,10 @@ static void entry_free(entry_t *entry) {
30
30
  free(entry);
31
31
  }
32
32
 
33
+ static inline double min(double a, double b) { return a < b ? a : b; }
34
+
35
+ static inline double max(double a, double b) { return a > b ? a : b; }
36
+
33
37
  static void merge_entry(entry_t *found, const entry_t *entry) {
34
38
  if (entry->type == sym_gauge) {
35
39
  if (entry->multiprocess_mode == sym_min) {
@@ -101,7 +105,10 @@ static int add_parsed_name(entry_t *entry) {
101
105
  }
102
106
 
103
107
  static int entry_lexical_comparator(const entry_t **a, const entry_t **b) {
104
- size_t min_length = min((*a)->json_size, (*b)->json_size);
108
+ size_t size_a = (*a)->json_size;
109
+ size_t size_b = (*b)->json_size;
110
+ size_t min_length = size_a < size_b ? size_a : size_b;
111
+
105
112
  return strncmp((*a)->json, (*b)->json, min_length);
106
113
  }
107
114
 
@@ -10,8 +10,6 @@
10
10
  #define DBL_DECIMAL_DIG 17
11
11
  #endif
12
12
 
13
- // inline min_t()
14
-
15
13
  static inline int is_valid(const jsmntok_t *token) { return token->start < token->end && token->start >= 0; }
16
14
  static inline int valid_not_null(const entry_t *entry, const jsmntok_t *token) {
17
15
  static const char null_s[] = "null";
@@ -10,16 +10,6 @@
10
10
  #define UNUSED(x) x
11
11
  #endif
12
12
 
13
- #define min(a,b) \
14
- ({ __typeof__ (a) _a = (a); \
15
- __typeof__ (b) _b = (b); \
16
- _a < _b ? _a : _b; })
17
-
18
- #define max(a,b) \
19
- ({ __typeof__ (a) _a = (a); \
20
- __typeof__ (b) _b = (b); \
21
- _a > _b ? _a : _b; })
22
-
23
13
  NORETURN(void raise_last_exception());
24
14
  void save_exception(VALUE exception, const char *fmt, ...);
25
15
 
Binary file
@@ -1,5 +1,5 @@
1
1
  module Prometheus
2
2
  module Client
3
- VERSION = '0.7.0.beta42'.freeze
3
+ VERSION = '0.7.0.beta43'.freeze
4
4
  end
5
5
  end
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2016 David Leeds
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,90 @@
1
+ # hashmap
2
+ Flexible hashmap implementation in C using open addressing and linear probing for collision resolution.
3
+
4
+ ### Summary
5
+ This project came into existence because there are a notable lack of flexible and easy to use data structures available in C. Sure, higher level languages have built-in libraries, but plenty of embedded projects or higher level libraries start with core C code. It was undesirable to add a bulky library like Glib as a dependency to my projects, or grapple with a restrictive license agreement. Searching for "C hashmap" yielded results with questionable algorithms and code quality, projects with difficult or inflexible interfaces, or projects with less desirable licenses. I decided it was time to create my own.
6
+
7
+
8
+ ### Goals
9
+ * **To scale gracefully to the full capacity of the numeric primitives in use.** E.g. on a 32-bit machine, you should be able to load a billion+ entries without hitting any bugs relating to integer overflows. Lookups on a hashtable with a billion entries should be performed in close to constant time, no different than lookups in a hashtable with 20 entries. Automatic rehashing occurs and maintains a load factor of 0.75 or less.
10
+ * **To provide a clean and easy-to-use interface.** C data structures often struggle to strike a balance between flexibility and ease of use. To this end, I provided a generic interface using void pointers for keys and data, and macros to generate type-specific wrapper functions, if desired.
11
+ * **To enable easy iteration and safe entry removal during iteration.** Applications often need these features, and the data structure should not hold them back. Both an iterator interface and a foreach function was provided to satisfy various use-cases. This hashmap also uses an open addressing scheme, which has superior iteration performance to a similar hashmap implemented using separate chaining (buckets with linked lists). This is because fewer instructions are needed per iteration, and array traversal has superior cache performance than linked list traversal.
12
+ * **To use a very unrestrictive software license.** Using no license was an option, but I wanted to allow the code to be tracked, simply for my own edification. I chose the MIT license because it is the most common open source license in use, and it grants full rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell the code. Basically, take this code and do what you want with it. Just be nice and leave the license comment and my name at top of the file. Feel free to add your name if you are modifying and redistributing.
13
+
14
+ ### Code Example
15
+ ```C
16
+ #include <stdlib.h>
17
+ #include <stdio.h>
18
+
19
+ #include <hashmap.h>
20
+
21
+ /* Some sample data structure with a string key */
22
+ struct blob {
23
+ char key[32];
24
+ size_t data_len;
25
+ unsigned char data[1024];
26
+ };
27
+
28
+ /* Declare type-specific blob_hashmap_* functions with this handy macro */
29
+ HASHMAP_FUNCS_CREATE(blob, const char, struct blob)
30
+
31
+ struct blob *blob_load(void)
32
+ {
33
+ struct blob *b;
34
+ /*
35
+ * Hypothetical function that allocates and loads blob structures
36
+ * from somewhere. Returns NULL when there are no more blobs to load.
37
+ */
38
+ return b;
39
+ }
40
+
41
+ /* Hashmap structure */
42
+ struct hashmap map;
43
+
44
+ int main(int argc, char **argv)
45
+ {
46
+ struct blob *b;
47
+ struct hashmap_iter *iter;
48
+
49
+ /* Initialize with default string key functions and init size */
50
+ hashmap_init(&map, hashmap_hash_string, hashmap_compare_string, 0);
51
+
52
+ /* Load some sample data into the map and discard duplicates */
53
+ while ((b = blob_load()) != NULL) {
54
+ if (blob_hashmap_put(&map, b->key, b) != b) {
55
+ printf("discarding blob with duplicate key: %s\n", b->key);
56
+ free(b);
57
+ }
58
+ }
59
+
60
+ /* Lookup a blob with key "AbCdEf" */
61
+ b = blob_hashmap_get(&map, "AbCdEf");
62
+ if (b) {
63
+ printf("Found blob[%s]\n", b->key);
64
+ }
65
+
66
+ /* Iterate through all blobs and print each one */
67
+ for (iter = hashmap_iter(&map); iter; iter = hashmap_iter_next(&map, iter)) {
68
+ printf("blob[%s]: data_len %zu bytes\n", blob_hashmap_iter_get_key(iter),
69
+ blob_hashmap_iter_get_data(iter)->data_len);
70
+ }
71
+
72
+ /* Remove all blobs with no data */
73
+ iter = hashmap_iter(&map);
74
+ while (iter) {
75
+ b = blob_hashmap_iter_get_data(iter);
76
+ if (b->data_len == 0) {
77
+ iter = hashmap_iter_remove(&map, iter);
78
+ free(b);
79
+ } else {
80
+ iter = hashmap_iter_next(&map, iter);
81
+ }
82
+ }
83
+
84
+ /* Free all allocated resources associated with map and reset its state */
85
+ hashmap_destroy(&map);
86
+
87
+ return 0;
88
+ }
89
+
90
+ ```
@@ -0,0 +1 @@
1
+ theme: jekyll-theme-slate