1 /* key-gen.c --- manufacturing sequential keys for some db tables
3 * ====================================================================
4 * Copyright (c) 2000-2004 CollabNet. All rights reserved.
6 * This software is licensed as described in the file COPYING, which
7 * you should have received as part of this distribution. The terms
8 * are also available at http://subversion.tigris.org/license-1.html.
9 * If newer versions of this license are posted there, you may use a
10 * newer version instead, at your option.
12 * This software consists of voluntary contributions made by many
13 * individuals. For exact contribution history, see the revision
14 * history and logs, available at http://subversion.tigris.org/.
15 * ====================================================================
18 #ifndef SVN_LIBSVN_FS_KEY_GEN_H
19 #define SVN_LIBSVN_FS_KEY_GEN_H
23 #include "svn_types.h"
27 #endif /* __cplusplus */
30 /* The alphanumeric keys passed in and out of svn_fs_base__next_key
31 are guaranteed never to be longer than this many bytes,
32 *including* the trailing null byte. It is therefore safe
33 to declare a key as "char key[MAX_KEY_SIZE]".
35 Note that this limit will be a problem if the number of
36 keys in a table ever exceeds
38 18217977168218728251394687124089371267338971528174
39 76066745969754933395997209053270030282678007662838
40 67331479599455916367452421574456059646801054954062
41 15017704234999886990788594743994796171248406730973
42 80736524850563115569208508785942830080999927310762
43 50733948404739350551934565743979678824151197232629
46 but that's a risk we'll live with for now. */
47 #define MAX_KEY_SIZE 200
49 /* In the `representations' and `strings', the value at this key is
50 the key to use when storing a new rep or string. */
51 #define NEXT_KEY_KEY "next-key"
54 /* Return the value of the string of digits at DATA as an ASCII
55 decimal number. The string is at most LEN bytes long. The value
56 of the number is at most MAX. Set *END to the address of the first
57 byte after the number, or zero if an error occurred while
58 converting the number (overflow, for example).
60 We would like to use strtoul, but that family of functions is
61 locale-dependent, whereas we're trying to parse data in a
62 locale-independent format. */
64 apr_size_t
svn_fs_base__getsize(const char *data
, apr_size_t len
,
65 const char **endptr
, apr_size_t max
);
68 /* Store the ASCII decimal representation of VALUE at DATA. Return
69 the length of the representation if all goes well; return zero if
70 the result doesn't fit in LEN bytes. */
71 int svn_fs_base__putsize(char *data
, apr_size_t len
, apr_size_t value
);
74 /* Generate the next key after a given alphanumeric key.
76 * The first *LEN bytes of THIS are an ascii representation of a
77 * number in base 36: digits 0-9 have their usual values, and a-z have
80 * The new key is stored in NEXT, null-terminated. NEXT must be at
81 * least *LEN + 2 bytes long -- one extra byte to hold a possible
82 * overflow column, and one for null termination. On return, *LEN
83 * will be set to the length of the new key, not counting the null
84 * terminator. In other words, the outgoing *LEN will be either equal
85 * to the incoming, or to the incoming + 1.
87 * If THIS contains anything other than digits and lower-case
88 * alphabetic characters, or if it starts with `0' but is not the
89 * string "0", then *LEN is set to zero and the effect on NEXT
92 void svn_fs_base__next_key(const char *this, apr_size_t
*len
, char *next
);
95 /* Compare two strings A and B as base-36 alphanumeric keys.
97 * Return -1, 0, or 1 if A is less than, equal to, or greater than B,
100 int svn_fs_base__key_compare(const char *a
, const char *b
);
102 /* Compare two strings A and B as base-36 alphanumber keys.
104 * Return TRUE iff both keys are NULL or both keys have the same
107 svn_boolean_t
svn_fs_base__same_keys(const char *a
, const char *b
);
112 #endif /* __cplusplus */
114 #endif /* SVN_LIBSVN_FS_KEY_GEN_H */