Artifactspublic-v0

curl

master
ply4 git calls223 ms288 KiB2 cachedprotocol v2
122 lines3.3 KiBRaw

hash

#include "hash.h"

This is the internal module for doing hash tables. A hash table uses a hash function to compute an index. On each index there is a separate linked list of entries.

Create a hash table. Add items. Retrieve items. Remove items. Destroy table.

Curl_hash_init

c
void Curl_hash_init(struct Curl_hash *h,
                    size_t slots,
                    Curl_hash_type type,
                    Curl_hash_dtor dtor);

The call initializes a struct Curl_hash.

  • slots is the number of entries to create in the hash table. Larger is better (faster lookups) but also uses more memory.
  • type selects how keys are hashed and compared. CURL_HASH_TYPE_BYTES treats keys as exact-length byte sequences. CURL_HASH_TYPE_SOCKET treats keys as native curl_socket_t values and requires key_len to equal sizeof(curl_socket_t).
  • dtor is a function pointer to a destructor called when an entry is removed from the table.

Curl_hash_add

c
void *
Curl_hash_add(struct Curl_hash *h, void *key, size_t key_len, void *p)

This call adds an entry to the hash. key points to the hash key and key_len is the length of the hash key. p is a custom pointer.

If there already was a match in the hash, that data is replaced with this new entry.

This function also lazily allocates the table if needed, as it is not done in the Curl_hash_init function.

Returns NULL on error, otherwise it returns a pointer to p.

Curl_hash_add2

c
void *Curl_hash_add2(struct Curl_hash *h, void *key, size_t key_len, void *p,
                     Curl_hash_elem_dtor dtor)

This works like Curl_hash_add but has an extra argument: dtor, which is a destructor call for this specific entry. When this entry is removed, this function is called instead of the function stored for the whole hash table.

Curl_hash_delete

c
int Curl_hash_delete(struct Curl_hash *h, void *key, size_t key_len);

This function removes an entry from the hash table. If successful, it returns zero. If the entry was not found, it returns 1.

Curl_hash_pick

c
void *Curl_hash_pick(struct Curl_hash *h, void *key, size_t key_len);

If there is an entry in the hash that matches the given key with size of key_len, that its custom pointer is returned. The pointer that was called p when the entry was added.

It returns NULL if there is no matching entry in the hash.

Curl_hash_destroy

c
void Curl_hash_destroy(struct Curl_hash *h);

This function destroys a hash and cleanups up all its related data. Calling it multiple times is fine.

Curl_hash_clean

c
void Curl_hash_clean(struct Curl_hash *h);

This function removes all the entries in the given hash.

Curl_hash_clean_with_criterium

c
void
Curl_hash_clean_with_criterium(struct Curl_hash *h, void *user,
                               int (*comp)(void *, void *))

This function removes all the entries in the given hash that matches the criterion. The provided comp function determines if the criteria is met by returning non-zero.

Curl_hash_count

c
size_t Curl_hash_count(struct Curl_hash *h)

Returns the number of entries stored in the hash.

1<!--
2Copyright (C) Daniel Stenberg, <daniel@haxx.se>, et al.
4SPDX-License-Identifier: curl
5-->
7# `hash`
9 #include "hash.h"
11This is the internal module for doing hash tables. A hash table uses a hash
12function to compute an index. On each index there is a separate linked list of
13entries.
15Create a hash table. Add items. Retrieve items. Remove items. Destroy table.
17## `Curl_hash_init`
19~~~c
20void Curl_hash_init(struct Curl_hash *h,
21 size_t slots,
22 Curl_hash_type type,
23 Curl_hash_dtor dtor);
24~~~
26The call initializes a `struct Curl_hash`.
28- `slots` is the number of entries to create in the hash table. Larger is
29 better (faster lookups) but also uses more memory.
30- `type` selects how keys are hashed and compared. `CURL_HASH_TYPE_BYTES`
31 treats keys as exact-length byte sequences. `CURL_HASH_TYPE_SOCKET` treats
32 keys as native `curl_socket_t` values and requires `key_len` to equal
33 `sizeof(curl_socket_t)`.
34- `dtor` is a function pointer to a destructor called when an entry is removed
35 from the table.
37## `Curl_hash_add`
39~~~c
40void *
41Curl_hash_add(struct Curl_hash *h, void *key, size_t key_len, void *p)
42~~~
44This call adds an entry to the hash. `key` points to the hash key and
45`key_len` is the length of the hash key. `p` is a custom pointer.
47If there already was a match in the hash, that data is replaced with this new
48entry.
50This function also lazily allocates the table if needed, as it is not done in
51the `Curl_hash_init` function.
53Returns NULL on error, otherwise it returns a pointer to `p`.
55## `Curl_hash_add2`
57~~~c
58void *Curl_hash_add2(struct Curl_hash *h, void *key, size_t key_len, void *p,
59 Curl_hash_elem_dtor dtor)
60~~~
62This works like `Curl_hash_add` but has an extra argument: `dtor`, which is a
63destructor call for this specific entry. When this entry is removed, this
64function is called instead of the function stored for the whole hash table.
66## `Curl_hash_delete`
68~~~c
69int Curl_hash_delete(struct Curl_hash *h, void *key, size_t key_len);
70~~~
72This function removes an entry from the hash table. If successful, it returns
73zero. If the entry was not found, it returns 1.
75## `Curl_hash_pick`
77~~~c
78void *Curl_hash_pick(struct Curl_hash *h, void *key, size_t key_len);
79~~~
81If there is an entry in the hash that matches the given `key` with size of
82`key_len`, that its custom pointer is returned. The pointer that was called
83`p` when the entry was added.
85It returns NULL if there is no matching entry in the hash.
87## `Curl_hash_destroy`
89~~~c
90void Curl_hash_destroy(struct Curl_hash *h);
91~~~
93This function destroys a hash and cleanups up all its related data. Calling it
94multiple times is fine.
96## `Curl_hash_clean`
98~~~c
99void Curl_hash_clean(struct Curl_hash *h);
100~~~
102This function removes all the entries in the given hash.
104## `Curl_hash_clean_with_criterium`
106~~~c
107void
108Curl_hash_clean_with_criterium(struct Curl_hash *h, void *user,
109 int (*comp)(void *, void *))
110~~~
112This function removes all the entries in the given hash that matches the
113criterion. The provided `comp` function determines if the criteria is met by
114returning non-zero.
116## `Curl_hash_count`
118~~~c
119size_t Curl_hash_count(struct Curl_hash *h)
120~~~
122Returns the number of entries stored in the hash.
Diagnostics4 git calls · 223 ms
CallStatusSizeTime0223 ms
discover200152 B2 ms
git.upload-pack discover
http.response.status_code=200
git.upstream.cf_ray=-
git.upstream.phase=ls-refs
git.upstream.dur_ms=2
git.response.bytes=152
git.server.agent=gitty/1.0
git.server.object_format=sha1
git.server.caps=agent ls-refs fetch object-format
git.server.fetch=shallow filter sideband-all
git.protocol.version=2
git.pkt.frames=8
git.pkt.data=6
git.pkt.flush=2
git.pkt.delim=0
git.pkt.bytes=152
git.pkt.payload.max=34
ls-refs200149 B · hit2 ms
git.upload-pack ls-refs
http.response.status_code=200
git.upstream.cf_ray=-
git.upstream.phase=ls-refs
git.upstream.dur_ms=2
git.response.bytes=149
git.response.cache=HIT
git.response.duration_ms=2
git.protocol.version=2
git.pkt.frames=3
git.pkt.data=2
git.pkt.flush=1
git.pkt.delim=0
git.pkt.bytes=149
git.pkt.payload.max=78
git.ls_refs.count=2
git.ls_refs.head=refs/heads/master
fetchblob:none · deepen 10200287 KiB · hit3 ms
git.upload-pack fetch
http.response.status_code=200
git.upstream.cf_ray=-
git.upstream.phase=fetch
git.upstream.dur_ms=3
git.response.bytes=293470
git.response.cache=HIT
git.response.duration_ms=3
git.fetch.filter=blob:none
git.fetch.filter.requested=tree:0
git.fetch.filter.fallback=blob:none
git.fetch.filter.learned=false
git.fetch.wants=31c911efe5652725e930f4d2e60c9060e5f6646d
git.fetch.haves.count=0
git.fetch.deepen=10
git.fetch.thin_pack=false
git.fetch.ofs_delta=true
git.protocol.version=2
git.pkt.frames=10
git.pkt.data=8
git.pkt.flush=1
git.pkt.delim=1
git.pkt.bytes=293470
git.pkt.payload.max=65516
git.sideband.band1.bytes=293354
git.sideband.band2.bytes=0
git.sideband.band3.bytes=0
git.pack.objects=87
git.pack.bytes=293354
git.pack.ofs_delta=0
git.pack.ref_delta=1
git.pack.chain.max=1
git.pack.trailer=6a646bcda6740bab42e321b51998b52ea15146c0
git.pack.full=86
Open pack map
fetch2001.3 KiB218 ms
git.upload-pack fetch
http.response.status_code=200
git.upstream.cf_ray=-
git.upstream.phase=fetch
git.upstream.dur_ms=218
git.response.bytes=1374
git.response.cache=MISS
git.response.duration_ms=218
git.fetch.wants=18aaa9153fe3d2593f7edad95eb07f6f0731bdcb
git.fetch.haves.count=0
git.fetch.deepen=0
git.fetch.thin_pack=false
git.fetch.ofs_delta=true
git.protocol.version=2
git.pkt.frames=3
git.pkt.data=2
git.pkt.flush=1
git.pkt.delim=0
git.pkt.bytes=1374
git.pkt.payload.max=1353
git.sideband.band1.bytes=1352
git.sideband.band2.bytes=0
git.sideband.band3.bytes=0

Each row is one HTTP round trip ply made to the git server for this page, on one timeline. discover asks what the server speaks, ls-refs lists branch tips, fetch brings objects by id. A hit was served by Workers Cache. Tap a row for its wire details.

Remote
https://5ad2236b39de4c8bd8f6270ea63f3ea9.artifacts.cloudflare.net/git/public-v0/curl.git
Ref
refs/heads/master
Commit
31c911efe5652725e930f4d2e60c9060e5f6646d
cf-ray
a5e2c4002beeaedd
Request
62f92da1…
Protocol
v2 · sha1
Agent
gitty/1.0
Filter
advertised
Fetch
shallow filter sideband-all
Capabilities
agent ls-refs fetch object-format