nxt_lvlhsh.c (72:e0cefa2185a5) nxt_lvlhsh.c (594:c89b29f038c4)
1
2/*
3 * Copyright (C) Igor Sysoev
4 * Copyright (C) NGINX, Inc.
5 */
6
7#include <nxt_main.h>
8

--- 174 unchanged lines hidden (view full) ---

183static nxt_int_t nxt_lvlhsh_free_level(nxt_lvlhsh_query_t *lhq, void **level,
184 nxt_uint_t size);
185static nxt_int_t nxt_lvlhsh_level_delete(nxt_lvlhsh_query_t *lhq, void **slot,
186 uint32_t key, nxt_uint_t nlvl);
187static nxt_int_t nxt_lvlhsh_bucket_delete(nxt_lvlhsh_query_t *lhq, void **bkt);
188static void *nxt_lvlhsh_level_each(nxt_lvlhsh_each_t *lhe, void **level,
189 nxt_uint_t nlvl, nxt_uint_t shift);
190static void *nxt_lvlhsh_bucket_each(nxt_lvlhsh_each_t *lhe);
1
2/*
3 * Copyright (C) Igor Sysoev
4 * Copyright (C) NGINX, Inc.
5 */
6
7#include <nxt_main.h>
8

--- 174 unchanged lines hidden (view full) ---

183static nxt_int_t nxt_lvlhsh_free_level(nxt_lvlhsh_query_t *lhq, void **level,
184 nxt_uint_t size);
185static nxt_int_t nxt_lvlhsh_level_delete(nxt_lvlhsh_query_t *lhq, void **slot,
186 uint32_t key, nxt_uint_t nlvl);
187static nxt_int_t nxt_lvlhsh_bucket_delete(nxt_lvlhsh_query_t *lhq, void **bkt);
188static void *nxt_lvlhsh_level_each(nxt_lvlhsh_each_t *lhe, void **level,
189 nxt_uint_t nlvl, nxt_uint_t shift);
190static void *nxt_lvlhsh_bucket_each(nxt_lvlhsh_each_t *lhe);
191static void *nxt_lvlhsh_level_peek(const nxt_lvlhsh_proto_t *proto,
192 void **level, nxt_uint_t nlvl);
193static void *nxt_lvlhsh_bucket_peek(const nxt_lvlhsh_proto_t *proto,
194 void **bkt);
191
192
193nxt_int_t
194nxt_lvlhsh_find(nxt_lvlhsh_t *lh, nxt_lvlhsh_query_t *lhq)
195{
196 void *slot;
197
198 slot = lh->slot;

--- 666 unchanged lines hidden (view full) ---

865 lhe->entry = 0;
866 }
867
868 return value;
869}
870
871
872void *
195
196
197nxt_int_t
198nxt_lvlhsh_find(nxt_lvlhsh_t *lh, nxt_lvlhsh_query_t *lhq)
199{
200 void *slot;
201
202 slot = lh->slot;

--- 666 unchanged lines hidden (view full) ---

869 lhe->entry = 0;
870 }
871
872 return value;
873}
874
875
876void *
877nxt_lvlhsh_peek(nxt_lvlhsh_t *lh, const nxt_lvlhsh_proto_t *proto)
878{
879 void **slot;
880
881 slot = lh->slot;
882
883 if (slot != NULL) {
884
885 if (nxt_lvlhsh_is_bucket(slot)) {
886 return nxt_lvlhsh_bucket_peek(proto, slot);
887 }
888
889 return nxt_lvlhsh_level_peek(proto, slot, 0);
890 }
891
892 return NULL;
893}
894
895
896static void *
897nxt_lvlhsh_level_peek(const nxt_lvlhsh_proto_t *proto, void **level,
898 nxt_uint_t nlvl)
899{
900 void **slot;
901 uintptr_t mask;
902 nxt_uint_t n, shift;
903
904 shift = proto->shift[nlvl];
905 mask = ((uintptr_t) 1 << shift) - 1;
906
907 level = nxt_lvlhsh_level(level, mask);
908
909 n = 0;
910
911 /* At least one valid level slot must present here. */
912
913 for ( ;; ) {
914 slot = level[n];
915
916 if (slot != NULL) {
917
918 if (nxt_lvlhsh_is_bucket(slot)) {
919 return nxt_lvlhsh_bucket_peek(proto, slot);
920 }
921
922 return nxt_lvlhsh_level_peek(proto, slot, nlvl + 1);
923 }
924
925 n++;
926 }
927}
928
929
930static void *
931nxt_lvlhsh_bucket_peek(const nxt_lvlhsh_proto_t *proto, void **bkt)
932{
933 void *value;
934 uint32_t *entry;
935
936 /* At least one valid entry must present here. */
937
938 for (entry = nxt_lvlhsh_bucket(proto, bkt);
939 nxt_lvlhsh_free_entry(entry);
940 entry += NXT_LVLHSH_ENTRY_SIZE)
941 {
942 /* void */
943 }
944
945 value = nxt_lvlhsh_entry_value(entry);
946 return value;
947}
948
949
950void *
873nxt_lvlhsh_alloc(void *data, size_t size)
874{
875 return nxt_memalign(size, size);
876}
877
878
879void
880nxt_lvlhsh_free(void *data, void *p)
881{
882 nxt_free(p);
883}
951nxt_lvlhsh_alloc(void *data, size_t size)
952{
953 return nxt_memalign(size, size);
954}
955
956
957void
958nxt_lvlhsh_free(void *data, void *p)
959{
960 nxt_free(p);
961}