]> CyberLeo.Net >> Repos - FreeBSD/releng/10.2.git/blob - contrib/subversion/subversion/libsvn_fs_fs/key-gen.h
- Copy stable/10@285827 to releng/10.2 in preparation for 10.2-RC1
[FreeBSD/releng/10.2.git] / contrib / subversion / subversion / libsvn_fs_fs / key-gen.h
1 /* key-gen.c --- manufacturing sequential keys for some db tables
2  *
3  * ====================================================================
4  *    Licensed to the Apache Software Foundation (ASF) under one
5  *    or more contributor license agreements.  See the NOTICE file
6  *    distributed with this work for additional information
7  *    regarding copyright ownership.  The ASF licenses this file
8  *    to you under the Apache License, Version 2.0 (the
9  *    "License"); you may not use this file except in compliance
10  *    with the License.  You may obtain a copy of the License at
11  *
12  *      http://www.apache.org/licenses/LICENSE-2.0
13  *
14  *    Unless required by applicable law or agreed to in writing,
15  *    software distributed under the License is distributed on an
16  *    "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17  *    KIND, either express or implied.  See the License for the
18  *    specific language governing permissions and limitations
19  *    under the License.
20  * ====================================================================
21  */
22
23 #ifndef SVN_LIBSVN_FS_KEY_GEN_H
24 #define SVN_LIBSVN_FS_KEY_GEN_H
25
26 #include <apr.h>
27
28 #include "svn_types.h"
29
30 #ifdef __cplusplus
31 extern "C" {
32 #endif /* __cplusplus */
33
34 \f
35 /* The alphanumeric keys passed in and out of svn_fs_fs__next_key
36    are guaranteed never to be longer than this many bytes,
37    *including* the trailing null byte.  It is therefore safe
38    to declare a key as "char key[MAX_KEY_SIZE]".
39
40    Note that this limit will be a problem if the number of
41    keys in a table ever exceeds
42
43        18217977168218728251394687124089371267338971528174
44        76066745969754933395997209053270030282678007662838
45        67331479599455916367452421574456059646801054954062
46        15017704234999886990788594743994796171248406730973
47        80736524850563115569208508785942830080999927310762
48        50733948404739350551934565743979678824151197232629
49        947748581376,
50
51    but that's a risk we'll live with for now. */
52 #define MAX_KEY_SIZE 200
53
54
55 /* Generate the next key after a given alphanumeric key.
56  *
57  * The first *LEN bytes of THIS are an ascii representation of a
58  * number in base 36: digits 0-9 have their usual values, and a-z have
59  * values 10-35.
60  *
61  * The new key is stored in NEXT, null-terminated.  NEXT must be at
62  * least *LEN + 2 bytes long -- one extra byte to hold a possible
63  * overflow column, and one for null termination.  On return, *LEN
64  * will be set to the length of the new key, not counting the null
65  * terminator.  In other words, the outgoing *LEN will be either equal
66  * to the incoming, or to the incoming + 1.
67  *
68  * If THIS contains anything other than digits and lower-case
69  * alphabetic characters, or if it starts with `0' but is not the
70  * string "0", then *LEN is set to zero and the effect on NEXT
71  * is undefined.
72  */
73 void svn_fs_fs__next_key(const char *this, apr_size_t *len, char *next);
74
75
76 /* Compare two strings A and B as base-36 alphanumeric keys.
77  *
78  * Return -1, 0, or 1 if A is less than, equal to, or greater than B,
79  * respectively.
80  */
81 int svn_fs_fs__key_compare(const char *a, const char *b);
82
83 /* Add two base-36 alphanumeric keys to get a third, the result. */
84 void svn_fs_fs__add_keys(const char *key1, const char *key2, char *result);
85
86
87 #ifdef __cplusplus
88 }
89 #endif /* __cplusplus */
90
91 #endif /* SVN_LIBSVN_FS_KEY_GEN_H */