1 | /* key-gen.c --- manufacturing sequential keys for some db tables |
---|
2 | * |
---|
3 | * ==================================================================== |
---|
4 | * Copyright (c) 2000-2004 CollabNet. All rights reserved. |
---|
5 | * |
---|
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. |
---|
11 | * |
---|
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 | * ==================================================================== |
---|
16 | */ |
---|
17 | |
---|
18 | #ifndef SVN_LIBSVN_FS_KEY_GEN_H |
---|
19 | #define SVN_LIBSVN_FS_KEY_GEN_H |
---|
20 | |
---|
21 | #include <apr.h> |
---|
22 | |
---|
23 | #include "svn_types.h" |
---|
24 | #include "private/svn_skel.h" /* ### for svn_fs_base__{get,put}size() */ |
---|
25 | |
---|
26 | #ifdef __cplusplus |
---|
27 | extern "C" { |
---|
28 | #endif /* __cplusplus */ |
---|
29 | |
---|
30 | |
---|
31 | /* The alphanumeric keys passed in and out of svn_fs_base__next_key |
---|
32 | are guaranteed never to be longer than this many bytes, |
---|
33 | *including* the trailing null byte. It is therefore safe |
---|
34 | to declare a key as "char key[MAX_KEY_SIZE]". |
---|
35 | |
---|
36 | Note that this limit will be a problem if the number of |
---|
37 | keys in a table ever exceeds |
---|
38 | |
---|
39 | 18217977168218728251394687124089371267338971528174 |
---|
40 | 76066745969754933395997209053270030282678007662838 |
---|
41 | 67331479599455916367452421574456059646801054954062 |
---|
42 | 15017704234999886990788594743994796171248406730973 |
---|
43 | 80736524850563115569208508785942830080999927310762 |
---|
44 | 50733948404739350551934565743979678824151197232629 |
---|
45 | 947748581376, |
---|
46 | |
---|
47 | but that's a risk we'll live with for now. */ |
---|
48 | #define MAX_KEY_SIZE 200 |
---|
49 | |
---|
50 | /* In many of the databases, the value at this key is the key to use |
---|
51 | when storing a new record. */ |
---|
52 | #define NEXT_KEY_KEY "next-key" |
---|
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_base__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_base__key_compare(const char *a, const char *b); |
---|
82 | |
---|
83 | /* Compare two strings A and B as base-36 alphanumber keys. |
---|
84 | * |
---|
85 | * Return TRUE iff both keys are NULL or both keys have the same |
---|
86 | * contents. |
---|
87 | */ |
---|
88 | svn_boolean_t svn_fs_base__same_keys(const char *a, const char *b); |
---|
89 | |
---|
90 | |
---|
91 | #ifdef __cplusplus |
---|
92 | } |
---|
93 | #endif /* __cplusplus */ |
---|
94 | |
---|
95 | #endif /* SVN_LIBSVN_FS_KEY_GEN_H */ |
---|