Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
N
nccf
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
This is an archived project. Repository and other project resources are read-only.
Show more breadcrumbs
702
Provoz
nccf
Commits
cfd1b1fe
Commit
cfd1b1fe
authored
Apr 25, 2013
by
Yorhel
Browse files
Options
Downloads
Patches
Plain Diff
deps: Update khash and yopt to their latest upstream versions
parent
09c44475
No related branches found
No related tags found
No related merge requests found
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
Makefile.am
+3
-0
3 additions, 0 deletions
Makefile.am
deps/khash.h
+103
-40
103 additions, 40 deletions
deps/khash.h
deps/yopt.h
+117
-111
117 additions, 111 deletions
deps/yopt.h
with
223 additions
and
151 deletions
Makefile.am
+
3
−
0
View file @
cfd1b1fe
...
...
@@ -38,3 +38,6 @@ EXTRA_DIST=ncdu.1 doc/ncdu.pod
ncdu.1
:
$(srcdir)/doc/ncdu.pod
pod2man
--center
"ncdu manual"
--release
"@PACKAGE@-@VERSION@"
"
$(
srcdir
)
/doc/ncdu.pod"
>
ncdu.1
update-deps
:
wget
-q
https://raw.github.com/attractivechaos/klib/master/khash.h
-O
"
$(
srcdir
)
/deps/khash.h"
wget
-q
http://g.blicky.net/ylib.git/plain/yopt.h
-O
"
$(
srcdir
)
/deps/yopt.h"
This diff is collapsed.
Click to expand it.
deps/khash.h
+
103
−
40
View file @
cfd1b1fe
...
...
@@ -33,7 +33,6 @@ int main() {
khiter_t k;
khash_t(32) *h = kh_init(32);
k = kh_put(32, h, 5, &ret);
if (!ret) kh_del(32, h, k);
kh_value(h, k) = 10;
k = kh_get(32, h, 10);
is_missing = (k == kh_end(h));
...
...
@@ -47,6 +46,10 @@ int main() {
*/
/*
2011-12-29 (0.2.7):
* Minor code clean up; no actual effect.
2011-09-16 (0.2.6):
* The capacity is a power of 2. This seems to dramatically improve the
...
...
@@ -113,7 +116,7 @@ int main() {
#include
<string.h>
#include
<limits.h>
/* compi
p
ler specific configuration */
/* compiler specific configuration */
#if UINT_MAX == 0xffffffffu
typedef
unsigned
int
khint32_t
;
...
...
@@ -128,7 +131,9 @@ typedef unsigned long long khint64_t;
#endif
#ifdef _MSC_VER
#define inline __inline
#define kh_inline __inline
#else
#define kh_inline inline
#endif
typedef
khint32_t
khint_t
;
...
...
@@ -154,39 +159,48 @@ typedef khint_t khiter_t;
#define kroundup32(x) (--(x), (x)|=(x)>>1, (x)|=(x)>>2, (x)|=(x)>>4, (x)|=(x)>>8, (x)|=(x)>>16, ++(x))
#endif
#ifndef kcalloc
#define kcalloc(N,Z) calloc(N,Z)
#endif
#ifndef kmalloc
#define kmalloc(Z) malloc(Z)
#endif
#ifndef krealloc
#define krealloc(P,Z) realloc(P,Z)
#endif
#ifndef kfree
#define kfree(P) free(P)
#endif
static
const
double
__ac_HASH_UPPER
=
0
.
77
;
#define KHASH_
DECLAR
E(name, khkey_t, khval_t)
\
#define
__
KHASH_
TYP
E(name, khkey_t, khval_t)
\
typedef struct { \
khint_t n_buckets, size, n_occupied, upper_bound; \
khint32_t *flags; \
khkey_t *keys; \
khval_t *vals; \
} kh_##name##_t; \
extern kh_##name##_t *kh_init_##name(); \
} kh_##name##_t;
#define __KHASH_PROTOTYPES(name, khkey_t, khval_t) \
extern kh_##name##_t *kh_init_##name(void); \
extern void kh_destroy_##name(kh_##name##_t *h); \
extern void kh_clear_##name(kh_##name##_t *h); \
extern khint_t kh_get_##name(const kh_##name##_t *h, khkey_t key); \
extern
void
kh_resize_##name(kh_##name##_t *h, khint_t new_n_buckets); \
extern
int
kh_resize_##name(kh_##name##_t *h, khint_t new_n_buckets); \
extern khint_t kh_put_##name(kh_##name##_t *h, khkey_t key, int *ret); \
extern void kh_del_##name(kh_##name##_t *h, khint_t x);
#define KHASH_INIT2(name, SCOPE, khkey_t, khval_t, kh_is_map, __hash_func, __hash_equal) \
typedef struct { \
khint_t n_buckets, size, n_occupied, upper_bound; \
khint32_t *flags; \
khkey_t *keys; \
khval_t *vals; \
} kh_##name##_t; \
SCOPE kh_##name##_t *kh_init_##name() { \
return (kh_##name##_t*)calloc(1, sizeof(kh_##name##_t)); \
#define __KHASH_IMPL(name, SCOPE, khkey_t, khval_t, kh_is_map, __hash_func, __hash_equal) \
SCOPE kh_##name##_t *kh_init_##name(void) { \
return (kh_##name##_t*)kcalloc(1, sizeof(kh_##name##_t)); \
} \
SCOPE void kh_destroy_##name(kh_##name##_t *h) \
{ \
if (h) { \
free(h->keys); free(h->flags);
\
free(h->vals);
\
free(h); \
k
free(
(void *)
h->keys);
k
free(h->flags); \
k
free(
(void *)
h->vals); \
k
free(h); \
} \
} \
SCOPE void kh_clear_##name(kh_##name##_t *h) \
...
...
@@ -210,8 +224,8 @@ static const double __ac_HASH_UPPER = 0.77;
return __ac_iseither(h->flags, i)? h->n_buckets : i; \
} else return 0; \
} \
SCOPE
void
kh_resize_##name(kh_##name##_t *h, khint_t new_n_buckets) \
{
/* This function uses 0.25*n_buck
t
es bytes of working space instead of [sizeof(key_t+val_t)+.25]*n_buckets. */
\
SCOPE
int
kh_resize_##name(kh_##name##_t *h, khint_t new_n_buckets) \
{
/* This function uses 0.25*n_bucke
t
s bytes of working space instead of [sizeof(key_t+val_t)+.25]*n_buckets. */
\
khint32_t *new_flags = 0; \
khint_t j = 1; \
{ \
...
...
@@ -219,11 +233,18 @@ static const double __ac_HASH_UPPER = 0.77;
if (new_n_buckets < 4) new_n_buckets = 4; \
if (h->size >= (khint_t)(new_n_buckets * __ac_HASH_UPPER + 0.5)) j = 0;
/* requested size is too small */
\
else {
/* hash table size to be changed (shrink or expand); rehash */
\
new_flags = (khint32_t*)malloc(__ac_fsize(new_n_buckets) * sizeof(khint32_t)); \
new_flags = (khint32_t*)kmalloc(__ac_fsize(new_n_buckets) * sizeof(khint32_t)); \
if (!new_flags) return -1; \
memset(new_flags, 0xaa, __ac_fsize(new_n_buckets) * sizeof(khint32_t)); \
if (h->n_buckets < new_n_buckets) {
/* expand */
\
h->keys = (khkey_t*)realloc(h->keys, new_n_buckets * sizeof(khkey_t)); \
if (kh_is_map) h->vals = (khval_t*)realloc(h->vals, new_n_buckets * sizeof(khval_t)); \
khkey_t *new_keys = (khkey_t*)krealloc((void *)h->keys, new_n_buckets * sizeof(khkey_t)); \
if (!new_keys) return -1; \
h->keys = new_keys; \
if (kh_is_map) { \
khval_t *new_vals = (khval_t*)krealloc((void *)h->vals, new_n_buckets * sizeof(khval_t)); \
if (!new_vals) return -1; \
h->vals = new_vals; \
} \
}
/* otherwise shrink */
\
} \
} \
...
...
@@ -256,22 +277,28 @@ static const double __ac_HASH_UPPER = 0.77;
} \
} \
if (h->n_buckets > new_n_buckets) {
/* shrink the hash table */
\
h->keys = (khkey_t*)realloc(h->keys, new_n_buckets * sizeof(khkey_t)); \
if (kh_is_map) h->vals = (khval_t*)realloc(h->vals, new_n_buckets * sizeof(khval_t)); \
h->keys = (khkey_t*)
k
realloc(
(void *)
h->keys, new_n_buckets * sizeof(khkey_t)); \
if (kh_is_map) h->vals = (khval_t*)
k
realloc(
(void *)
h->vals, new_n_buckets * sizeof(khval_t)); \
} \
free(h->flags);
/* free the working space */
\
k
free(h->flags);
/* free the working space */
\
h->flags = new_flags; \
h->n_buckets = new_n_buckets; \
h->n_occupied = h->size; \
h->upper_bound = (khint_t)(h->n_buckets * __ac_HASH_UPPER + 0.5); \
} \
return 0; \
} \
SCOPE khint_t kh_put_##name(kh_##name##_t *h, khkey_t key, int *ret) \
{ \
khint_t x; \
if (h->n_occupied >= h->upper_bound) {
/* update the hash table */
\
if (h->n_buckets > (h->size<<1)) kh_resize_##name(h, h->n_buckets - 1);
/* clear "deleted" elements */
\
else kh_resize_##name(h, h->n_buckets + 1);
/* expand the hash table */
\
if (h->n_buckets > (h->size<<1)) { \
if (kh_resize_##name(h, h->n_buckets - 1) < 0) {
/* clear "deleted" elements */
\
*ret = -1; return h->n_buckets; \
} \
} else if (kh_resize_##name(h, h->n_buckets + 1) < 0) {
/* expand the hash table */
\
*ret = -1; return h->n_buckets; \
} \
}
/* TODO: to implement automatically shrinking; resize() already support shrinking */
\
{ \
khint_t inc, k, i, site, last, mask = h->n_buckets - 1; \
...
...
@@ -311,8 +338,16 @@ static const double __ac_HASH_UPPER = 0.77;
} \
}
#define KHASH_DECLARE(name, khkey_t, khval_t) \
__KHASH_TYPE(name, khkey_t, khval_t) \
__KHASH_PROTOTYPES(name, khkey_t, khval_t)
#define KHASH_INIT2(name, SCOPE, khkey_t, khval_t, kh_is_map, __hash_func, __hash_equal) \
__KHASH_TYPE(name, khkey_t, khval_t) \
__KHASH_IMPL(name, SCOPE, khkey_t, khval_t, kh_is_map, __hash_func, __hash_equal)
#define KHASH_INIT(name, khkey_t, khval_t, kh_is_map, __hash_func, __hash_equal) \
KHASH_INIT2(name, static inline, khkey_t, khval_t, kh_is_map, __hash_func, __hash_equal)
KHASH_INIT2(name, static
kh_
inline, khkey_t, khval_t, kh_is_map, __hash_func, __hash_equal)
/* --- BEGIN OF HASH FUNCTIONS --- */
...
...
@@ -341,10 +376,10 @@ static const double __ac_HASH_UPPER = 0.77;
@param s Pointer to a null terminated string
@return The hash value
*/
static
inline
khint_t
__ac_X31_hash_string
(
const
char
*
s
)
static
kh_
inline
khint_t
__ac_X31_hash_string
(
const
char
*
s
)
{
khint_t
h
=
*
s
;
if
(
h
)
for
(
++
s
;
*
s
;
++
s
)
h
=
(
h
<<
5
)
-
h
+
*
s
;
khint_t
h
=
(
khint_t
)
*
s
;
if
(
h
)
for
(
++
s
;
*
s
;
++
s
)
h
=
(
h
<<
5
)
-
h
+
(
khint_t
)
*
s
;
return
h
;
}
/*! @function
...
...
@@ -358,7 +393,7 @@ static inline khint_t __ac_X31_hash_string(const char *s)
*/
#define kh_str_hash_equal(a, b) (strcmp(a, b) == 0)
static
inline
khint_t
__ac_Wang_hash
(
khint_t
key
)
static
kh_
inline
khint_t
__ac_Wang_hash
(
khint_t
key
)
{
key
+=
~
(
key
<<
15
);
key
^=
(
key
>>
10
);
...
...
@@ -426,7 +461,7 @@ static inline khint_t __ac_Wang_hash(khint_t key)
@param name Name of the hash table [symbol]
@param h Pointer to the hash table [khash_t(name)*]
@param k Key [type of keys]
@return Iterator to the found element, or kh_end(h) i
s
the element is absent [khint_t]
@return Iterator to the found element, or kh_end(h) i
f
the element is absent [khint_t]
*/
#define kh_get(name, h, k) kh_get_##name(h, k)
...
...
@@ -496,6 +531,34 @@ static inline khint_t __ac_Wang_hash(khint_t key)
*/
#define kh_n_buckets(h) ((h)->n_buckets)
/*! @function
@abstract Iterate over the entries in the hash table
@param h Pointer to the hash table [khash_t(name)*]
@param kvar Variable to which key will be assigned
@param vvar Variable to which value will be assigned
@param code Block of code to execute
*/
#define kh_foreach(h, kvar, vvar, code) { khint_t __i; \
for (__i = kh_begin(h); __i != kh_end(h); ++__i) { \
if (!kh_exist(h,__i)) continue; \
(kvar) = kh_key(h,__i); \
(vvar) = kh_val(h,__i); \
code; \
} }
/*! @function
@abstract Iterate over the values in the hash table
@param h Pointer to the hash table [khash_t(name)*]
@param vvar Variable to which value will be assigned
@param code Block of code to execute
*/
#define kh_foreach_value(h, vvar, code) { khint_t __i; \
for (__i = kh_begin(h); __i != kh_end(h); ++__i) { \
if (!kh_exist(h,__i)) continue; \
(vvar) = kh_val(h,__i); \
code; \
} }
/* More conenient interfaces */
/*! @function
...
...
This diff is collapsed.
Click to expand it.
deps/yopt.h
+
117
−
111
View file @
cfd1b1fe
/* ncdu - NCurses Disk Usage
Copyright (c) 2007-2012 Yoran Heling
/* Copyright (c) 2012-2013 Yoran Heling
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
...
...
@@ -20,7 +18,6 @@
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
/* This is a simple command-line option parser. Operation is similar to
...
...
@@ -48,7 +45,11 @@
*/
#ifndef YOPT_H
#define YOPT_H
#include
<string.h>
#include
<stdarg.h>
#include
<stdlib.h>
#include
<stdio.h>
...
...
@@ -73,13 +74,13 @@ typedef struct {
int
argsep
;
/* '--' found */
char
**
argv
;
char
*
sh
;
yopt_opt_t
*
opts
;
const
yopt_opt_t
*
opts
;
char
errbuf
[
128
];
}
yopt_t
;
/* opts must be an array of options, terminated with an option with val=0 */
static
inline
void
yopt_init
(
yopt_t
*
o
,
int
argc
,
char
**
argv
,
yopt_opt_t
*
opts
)
{
static
inline
void
yopt_init
(
yopt_t
*
o
,
int
argc
,
char
**
argv
,
const
yopt_opt_t
*
opts
)
{
o
->
argc
=
argc
;
o
->
argv
=
argv
;
o
->
opts
=
opts
;
...
...
@@ -89,7 +90,7 @@ static inline void yopt_init(yopt_t *o, int argc, char **argv, yopt_opt_t *opts)
}
static
inline
yopt_opt_t
*
_yopt_find
(
yopt_opt_t
*
o
,
const
char
*
v
)
{
static
inline
const
yopt_opt_t
*
_yopt_find
(
const
yopt_opt_t
*
o
,
const
char
*
v
)
{
const
char
*
tn
,
*
tv
;
for
(;
o
->
val
;
o
++
)
{
...
...
@@ -131,7 +132,7 @@ static inline int _yopt_err(yopt_t *o, char **val, const char *fmt, ...) {
* value will be in val.
*/
static
inline
int
yopt_next
(
yopt_t
*
o
,
char
**
val
)
{
yopt_opt_t
*
opt
;
const
yopt_opt_t
*
opt
;
char
sh
[
3
];
*
val
=
NULL
;
...
...
@@ -190,3 +191,8 @@ inshort:
o
->
sh
=
NULL
;
return
opt
->
val
;
}
#endif
/* vim: set noet sw=4 ts=4: */
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment