Hackfut Security File Manager
Current Path:
/opt/td-agent/embedded/lib/ruby/gems/2.4.0/gems/oj-3.7.12/ext/oj
opt
/
td-agent
/
embedded
/
lib
/
ruby
/
gems
/
2.4.0
/
gems
/
oj-3.7.12
/
ext
/
oj
/
📁
..
📄
.sitearchdir.-.oj.time
(0 B)
📄
Makefile
(9.43 KB)
📄
buf.h
(3.07 KB)
📄
cache8.c
(2.11 KB)
📄
cache8.h
(1.93 KB)
📄
circarray.c
(1.25 KB)
📄
circarray.h
(579 B)
📄
code.c
(5.2 KB)
📄
code.h
(974 B)
📄
compat.c
(8.35 KB)
📄
custom.c
(31.7 KB)
📄
dump.c
(29.51 KB)
📄
dump.h
(2.8 KB)
📄
dump_compat.c
(26.02 KB)
📄
dump_leaf.c
(5.47 KB)
📄
dump_object.c
(20.4 KB)
📄
dump_strict.c
(11.08 KB)
📄
encode.h
(1.78 KB)
📄
err.c
(1.24 KB)
📄
err.h
(2.53 KB)
📄
extconf.rb
(1.19 KB)
📄
fast.c
(42.43 KB)
📄
hash.c
(4.11 KB)
📄
hash.h
(1.9 KB)
📄
hash_test.c
(16.02 KB)
📄
mimic_json.c
(25.65 KB)
📄
object.c
(19.56 KB)
📄
odd.c
(5.37 KB)
📄
odd.h
(1.08 KB)
📄
oj.c
(69.29 KB)
📄
oj.h
(9.93 KB)
📄
oj.so
(1.08 MB)
📄
parse.c
(27.28 KB)
📄
parse.h
(3 KB)
📄
rails.c
(38.54 KB)
📄
rails.h
(392 B)
📄
reader.c
(6.06 KB)
📄
reader.h
(2.84 KB)
📄
resolve.c
(2.35 KB)
📄
resolve.h
(351 B)
📄
rxclass.c
(2.96 KB)
📄
rxclass.h
(653 B)
📄
saj.c
(17.11 KB)
📄
scp.c
(5.54 KB)
📄
sparse.c
(22.78 KB)
📄
stream_writer.c
(10.16 KB)
📄
strict.c
(5.4 KB)
📄
string_writer.c
(13.4 KB)
📄
trace.c
(2.08 KB)
📄
trace.h
(838 B)
📄
util.c
(3.37 KB)
📄
util.h
(313 B)
📄
val_stack.c
(3.63 KB)
📄
val_stack.h
(4.79 KB)
📄
wab.c
(15.25 KB)
Editing: hash.c
/* hash.c * Copyright (c) 2011, Peter Ohler * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: * * - Redistributions of source code must retain the above copyright notice, this * list of conditions and the following disclaimer. * * - Redistributions in binary form must reproduce the above copyright notice, * this list of conditions and the following disclaimer in the documentation * and/or other materials provided with the distribution. * * - Neither the name of Peter Ohler nor the names of its contributors may be * used to endorse or promote products derived from this software without * specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #include "hash.h" #include <stdint.h> #define HASH_MASK 0x000003FF #define HASH_SLOT_CNT 1024 typedef struct _keyVal { struct _keyVal *next; const char *key; size_t len; VALUE val; } *KeyVal; struct _hash { struct _keyVal slots[HASH_SLOT_CNT]; }; struct _hash class_hash; struct _hash intern_hash; // almost the Murmur hash algorithm #define M 0x5bd1e995 #define C1 0xCC9E2D51 #define C2 0x1B873593 #define N 0xE6546B64 static uint32_t hash_calc(const uint8_t *key, size_t len) { const uint8_t *end = key + len; const uint8_t *endless = key + (len / 4 * 4); uint32_t h = (uint32_t)len; uint32_t k; while (key < endless) { k = (uint32_t)*key++; k |= (uint32_t)*key++ << 8; k |= (uint32_t)*key++ << 16; k |= (uint32_t)*key++ << 24; k *= M; k ^= k >> 24; h *= M; h ^= k * M; } if (1 < end - key) { uint16_t k16 = (uint16_t)*key++; k16 |= (uint16_t)*key++ << 8; h ^= k16 << 8; } if (key < end) { h ^= *key; } h *= M; h ^= h >> 13; h *= M; h ^= h >> 15; return h; } void oj_hash_init() { memset(class_hash.slots, 0, sizeof(class_hash.slots)); memset(intern_hash.slots, 0, sizeof(intern_hash.slots)); } // if slotp is 0 then just lookup static VALUE hash_get(Hash hash, const char *key, size_t len, VALUE **slotp, VALUE def_value) { uint32_t h = hash_calc((const uint8_t*)key, len) & HASH_MASK; KeyVal bucket = hash->slots + h; if (0 != bucket->key) { KeyVal b; for (b = bucket; 0 != b; b = b->next) { if (len == b->len && 0 == strncmp(b->key, key, len)) { *slotp = &b->val; return b->val; } bucket = b; } } if (0 != slotp) { if (0 != bucket->key) { KeyVal b = ALLOC(struct _keyVal); b->next = 0; bucket->next = b; bucket = b; } bucket->key = oj_strndup(key, len); bucket->len = len; bucket->val = def_value; *slotp = &bucket->val; } return def_value; } void oj_hash_print() { int i; KeyVal b; for (i = 0; i < HASH_SLOT_CNT; i++) { printf("%4d:", i); for (b = class_hash.slots + i; 0 != b && 0 != b->key; b = b->next) { printf(" %s", b->key); } printf("\n"); } } VALUE oj_class_hash_get(const char *key, size_t len, VALUE **slotp) { return hash_get(&class_hash, key, len, slotp, Qnil); } ID oj_attr_hash_get(const char *key, size_t len, ID **slotp) { return (ID)hash_get(&intern_hash, key, len, (VALUE**)slotp, 0); } char* oj_strndup(const char *s, size_t len) { char *d = ALLOC_N(char, len + 1); memcpy(d, s, len); d[len] = '\0'; return d; }
Upload File
Create Folder