Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(515)

Delta Between Two Patch Sets: src/pkg/runtime/hashmap.h

Issue 4047047: code review 4047047: runtime: automaticaly generated Go declarations for C v... (Closed)
Left Patch Set: code review 4047047: runtime: automaticaly generated Go declarations for C v... Created 14 years, 1 month ago
Right Patch Set: code review 4047047: runtime: generate Go defs for C types. Created 14 years, 1 month ago
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
Left: Side by side diff | Download
Right: Side by side diff | Download
« no previous file with change/comment | « src/pkg/runtime/freebsd/runtime_defs.go ('k') | src/pkg/runtime/hashmap.c » ('j') | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
1 // Copyright 2009 The Go Authors. All rights reserved. 1 // Copyright 2009 The Go Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style 2 // Use of this source code is governed by a BSD-style
3 // license that can be found in the LICENSE file. 3 // license that can be found in the LICENSE file.
4 4
5 /* A hash table. 5 /* A hash table.
6 Example, hashing nul-terminated char*s: 6 Example, hashing nul-terminated char*s:
7 hash_hash_t str_hash (void *v) { 7 hash_hash_t str_hash (void *v) {
8 char *s; 8 char *s;
9 hash_hash_t hash = 0; 9 hash_hash_t hash = 0;
10 for (s = *(char **)v; *s != 0; s++) { 10 for (s = *(char **)v; *s != 0; s++) {
11 hash = (hash ^ *s) * 2654435769U; 11 hash = (hash ^ *s) * 2654435769U;
12 } 12 }
13 return (hash); 13 return (hash);
14 } 14 }
15 int str_eq (void *a, void *b) { 15 int str_eq (void *a, void *b) {
16 return (strcmp (*(char **)a, *(char **)b) == 0); 16 return (strcmp (*(char **)a, *(char **)b) == 0);
17 } 17 }
18 void str_del (void *arg, void *data) { 18 void str_del (void *arg, void *data) {
19 *(char **)arg = *(char **)data; 19 *(char **)arg = *(char **)data;
20 } 20 }
21 21
22 » struct Hmap *h = hash_new (sizeof (char *), &str_hash, &str_eq, &str_del , 3, 12, 15); 22 » struct hash *h = hash_new (sizeof (char *), &str_hash, &str_eq, &str_del , 3, 12, 15);
23 ... 3=> 2**3 entries initial size 23 ... 3=> 2**3 entries initial size
24 ... 12=> 2**12 entries before sprouting sub-tables 24 ... 12=> 2**12 entries before sprouting sub-tables
25 ... 15=> number of adjacent probes to attempt before growing 25 ... 15=> number of adjacent probes to attempt before growing
26 26
27 Example lookup: 27 Example lookup:
28 char *key = "foobar"; 28 char *key = "foobar";
29 char **result_ptr; 29 char **result_ptr;
30 if (hash_lookup (h, &key, (void **) &result_ptr)) { 30 if (hash_lookup (h, &key, (void **) &result_ptr)) {
31 printf ("found in table: %s\n", *result_ptr); 31 printf ("found in table: %s\n", *result_ptr);
32 } else { 32 } else {
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after
150 // void hash_iter_init (struct hash *h, struct hash_iter *it); 150 // void hash_iter_init (struct hash *h, struct hash_iter *it);
151 151
152 /* Return the next used entry in the table which which *it was initialized. */ 152 /* Return the next used entry in the table which which *it was initialized. */
153 // void *hash_next (struct hash_iter *it); 153 // void *hash_next (struct hash_iter *it);
154 154
155 /*---- test interface ----*/ 155 /*---- test interface ----*/
156 /* Call (*data_visit) (arg, level, data) for every data entry in the table, 156 /* Call (*data_visit) (arg, level, data) for every data entry in the table,
157 whether used or not. "level" is the subtable level, 0 means first level. */ 157 whether used or not. "level" is the subtable level, 0 means first level. */
158 /* TESTING ONLY: DO NOT USE THIS ROUTINE IN NORMAL CODE */ 158 /* TESTING ONLY: DO NOT USE THIS ROUTINE IN NORMAL CODE */
159 // void hash_visit (struct hash *h, void (*data_visit) (void *arg, int32 level, void *data), void *arg); 159 // void hash_visit (struct hash *h, void (*data_visit) (void *arg, int32 level, void *data), void *arg);
LEFTRIGHT

Powered by Google App Engine
RSS Feeds Recent Issues | This issue
This is Rietveld f62528b