]> CyberLeo.Net >> Repos - FreeBSD/releng/10.0.git/blob - contrib/subversion/subversion/libsvn_fs_base/key-gen.h
- Copy stable/10 (r259064) to releng/10.0 as part of the
[FreeBSD/releng/10.0.git] / contrib / subversion / subversion / libsvn_fs_base / 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 #include "private/svn_skel.h"  /* ### for svn_fs_base__{get,put}size() */
30
31 #ifdef __cplusplus
32 extern "C" {
33 #endif /* __cplusplus */
34
35 \f
36 /* The alphanumeric keys passed in and out of svn_fs_base__next_key
37    are guaranteed never to be longer than this many bytes,
38    *including* the trailing null byte.  It is therefore safe
39    to declare a key as "char key[MAX_KEY_SIZE]".
40
41    Note that this limit will be a problem if the number of
42    keys in a table ever exceeds
43
44        18217977168218728251394687124089371267338971528174
45        76066745969754933395997209053270030282678007662838
46        67331479599455916367452421574456059646801054954062
47        15017704234999886990788594743994796171248406730973
48        80736524850563115569208508785942830080999927310762
49        50733948404739350551934565743979678824151197232629
50        947748581376,
51
52    but that's a risk we'll live with for now. */
53 #define MAX_KEY_SIZE 200
54
55 /* In many of the databases, the value at this key is the key to use
56    when storing a new record. */
57 #define NEXT_KEY_KEY "next-key"
58
59
60 /* Generate the next key after a given alphanumeric key.
61  *
62  * The first *LEN bytes of THIS are an ascii representation of a
63  * number in base 36: digits 0-9 have their usual values, and a-z have
64  * values 10-35.
65  *
66  * The new key is stored in NEXT, null-terminated.  NEXT must be at
67  * least *LEN + 2 bytes long -- one extra byte to hold a possible
68  * overflow column, and one for null termination.  On return, *LEN
69  * will be set to the length of the new key, not counting the null
70  * terminator.  In other words, the outgoing *LEN will be either equal
71  * to the incoming, or to the incoming + 1.
72  *
73  * If THIS contains anything other than digits and lower-case
74  * alphabetic characters, or if it starts with `0' but is not the
75  * string "0", then *LEN is set to zero and the effect on NEXT
76  * is undefined.
77  */
78 void svn_fs_base__next_key(const char *this, apr_size_t *len, char *next);
79
80
81 /* Compare two strings A and B as base-36 alphanumeric keys.
82  *
83  * Return -1, 0, or 1 if A is less than, equal to, or greater than B,
84  * respectively.
85  */
86 int svn_fs_base__key_compare(const char *a, const char *b);
87
88 /* Compare two strings A and B as base-36 alphanumber keys.
89  *
90  * Return TRUE iff both keys are NULL or both keys have the same
91  * contents.
92  */
93 svn_boolean_t svn_fs_base__same_keys(const char *a, const char *b);
94
95
96 #ifdef __cplusplus
97 }
98 #endif /* __cplusplus */
99
100 #endif /* SVN_LIBSVN_FS_KEY_GEN_H */