File: tkrzw-doc.py

package info (click to toggle)
tkrzw-python 0.1.32-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 436 kB
  • sloc: cpp: 4,723; python: 1,989; makefile: 96
file content (1884 lines) | stat: -rw-r--r-- 67,713 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
#! /usr/bin/python3
# -*- coding: utf-8 -*-
#--------------------------------------------------------------------------------------------------
# API document
#
# Copyright 2020 Google LLC
# Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file
# except in compliance with the License.  You may obtain a copy of the License at
#     https://www.apache.org/licenses/LICENSE-2.0
# Unless required by applicable law or agreed to in writing, software distributed under the
# License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
# either express or implied.  See the License for the specific language governing permissions
# and limitations under the License.
#--------------------------------------------------------------------------------------------------


class Utility:
  """
  Library utilities.
  """

  VERSION = "0.0.0"
  """The package version numbers."""
  OS_NAME = "unknown"
  """The recognized OS name."""
  PAGE_SIZE = 4096
  """The size of a memory page on the OS."""
  INT32MIN = -2 ** 31
  """The minimum value of int32."""
  INT32MAX = 2 ** 31 - 1
  """The maximum value of int32."""
  UINT32MAX = 2 ** 32 - 1
  """The maximum value of uint32."""
  INT64MIN = -2 ** 63
  """The minimum value of int64."""
  INT64MAX = 2 ** 63 - 1
  """The maximum value of int64."""
  UINT64MAX = 2 ** 64 - 1
  """The maximum value of uint64."""

  @classmethod
  def GetMemoryCapacity(cls):
    """
    Gets the memory capacity of the platform.

    :return: The memory capacity of the platform in bytes, or -1 on failure.
    """
    pass  # native code

  @classmethod
  def GetMemoryUsage(cls):
    """
    Gets the current memory usage of the process.

    :return: The current memory usage of the process in bytes, or -1 on failure.
    """
    pass  # native code

  @classmethod
  def PrimaryHash(cls, data, num_buckets=None):
    """
    Primary hash function for the hash database.

    :param data: The data to calculate the hash value for.
    :param num_buckets: The number of buckets of the hash table.  If it is omitted, UINT64MAX is set.
    :return: The hash value.
    """
    pass  # native code

  @classmethod
  def SecondaryHash(cls, data, num_shards=None):
    """
    Secondary hash function for sharding.

    :param data: The data to calculate the hash value for.
    :param num_shards: The number of shards.  If it is omitted, UINT64MAX is set.
    :return: The hash value.
    """
    pass  # native code

  @classmethod
  def EditDistanceLev(cls, a, b):
    """
    Gets the Levenshtein edit distance of two Unicode strings.

    :param a: A Unicode string.
    :param b: The other Unicode string.
    :return: The Levenshtein edit distance of the two strings.
    """
    pass  # native code

  @classmethod
  def SerializeInt(cls, num):
    """
    Serializes an integer into a big-endian binary sequence.

    :param num: an integer.
    :return: The result binary sequence.
    """
    pass  # native code

  @classmethod
  def DeserializeInt(cls, data):
    """
    Deserializes a big-endian binary sequence into an integer.

    :param data: a binary sequence.
    :return: The result integer.
    """
    pass  # native code

  @classmethod
  def SerializeFloat(cls, num):
    """
    Serializes a floating-point number into a big-endian binary sequence.

    :param num: a floating-point number.
    :return: The result binary sequence.
    """
    pass  # native code

  @classmethod
  def DeserializeFloat(cls, data):
    """
    Deserializes a big-endian binary sequence into a floating-point number.

    :param data: a binary sequence.
    :return: The result floating-point number.
    """
    pass  # native code


class Status:
  """
  Status of operations.
  """

  SUCCESS = 0
  """Success."""
  UNKNOWN_ERROR = 1
  """Generic error whose cause is unknown."""
  SYSTEM_ERROR = 2
  """Generic error from underlying systems."""
  NOT_IMPLEMENTED_ERROR = 3
  """Error that the feature is not implemented."""
  PRECONDITION_ERROR = 4
  """Error that a precondition is not met."""
  INVALID_ARGUMENT_ERROR = 5
  """Error that a given argument is invalid."""
  CANCELED_ERROR = 6
  """Error that the operation is canceled."""
  NOT_FOUND_ERROR = 7
  """Error that a specific resource is not found."""
  PERMISSION_ERROR = 8
  """Error that the operation is not permitted."""
  INFEASIBLE_ERROR = 9
  """Error that the operation is infeasible."""
  DUPLICATION_ERROR = 10
  """Error that a specific resource is duplicated."""
  BROKEN_DATA_ERROR = 11
  """Error that internal data are broken."""
  NETWORK_ERROR = 12
  """Error caused by networking failure."""
  APPLICATION_ERROR = 13
  """Generic error caused by the application logic."""

  def __init__(self, code=SUCCESS, message=""):
    """
    Sets the code and the message.

    :param code: The status code.  This can be omitted and then SUCCESS is set.
    :param message: An arbitrary status message.  This can be omitted and the an empty string is set.
    """
    pass  # native code

  def __repr__(self):
    """
    Returns a string representation of the object.

    :return: The string representation of the object.
    """
    pass  # native code

  def __str__(self):
    """
    Returns a string representation of the content.

    :return: The string representation of the content.
    """
    pass  # native code

  def __eq__(self, rhs):
    """
    Returns true if the given object is equivalent to this object.
    
    :return: True if the given object is equivalent to this object.

    This supports comparison between a status object and a status code number.
    """
    pass  # native code

  def Set(self, code=SUCCESS, message=""):
    """
    Sets the code and the message.

    :param code: The status code.  This can be omitted and then SUCCESS is set.
    :param message: An arbitrary status message.  This can be omitted and the an empty string is set.
    """
    pass  # native code

  def Join(self, rht):
    """
    Assigns the internal state from another status object only if the current state is success.

    :param rhs: The status object.
    """
    pass  # native code

  def GetCode(self):
    """
    Gets the status code.

    :return: The status code.
    """
    pass  # native code

  def GetMessage(self):
    """
    Gets the status message.

    :return: The status message.
    """
    pass  # native code

  def IsOK(self):
    """
    Returns true if the status is success.

    :return: True if the status is success, or False on failure.
    """
    pass  # native code

  def OrDie(self):
    """
    Raises an exception if the status is not success.

    :raise StatusException: An exception containing the status object.
    """
    pass  # native code

  @classmethod
  def CodeName(cls, code):
    """
    Gets the string name of a status code.

    :param: code The status code.
    :return: The name of the status code.
    """
    pass  # native code


class Future:
  """
  Future containing a status object and extra data.

  Future objects are made by methods of AsyncDBM.  Every future object should be destroyed by the "Destruct" method or the "Get" method to free resources.  This class implements the awaitable protocol so an instance is usable with the "await" sentence.
  """

  def __init__(self):
    """
    The constructor cannot be called directly.  Use methods of AsyncDBM.
    """
    pass  # native code

  def __repr__(self):
    """
    Returns A string representation of the object.

    :return: The string representation of the object.
    """
    pass  # native code

  def __str__(self):
    """
    Returns a string representation of the content.

    :return: The string representation of the content.
    """
    pass  # native code

  def __await__(self):
    """
    Waits for the operation to be done and returns an iterator.

    :return: The iterator which stops immediately.
    """
    pass  # native code

  def Wait(self, timeout=-1):
    """
    Waits for the operation to be done.

    :param timeout: The waiting time in seconds.  If it is negative, no timeout is set.
    :return: True if the operation has done.  False if timeout occurs.
    """
    pass  # native code

  def Get(self):
    """
    Waits for the operation to be done and gets the result status.

    :return: The result status and extra data if any.  The existence and the type of extra data depends on the operation which makes the future.  For DBM#Get, a tuple of the status and the retrieved value is returned.  For DBM#Set and DBM#Remove, the status object itself is returned.

    The internal resource is released by this method.  "Wait" and "Get" cannot be called after calling this method.
    """
    pass  # native code


class StatusException(RuntimeError):
  """
  Exception to convey the status of operations.
  """

  def __init__(self, status):
    """
    Sets the status.

    :param status: The status object.
    """
    pass  # native code

  def __repr__(self):
    """
    Returns A string representation of the object.

    :return: The string representation of the object.
    """
    pass  # native code

  def __str__(self):
    """
    Returns A string representation of the content.

    :return: The string representation of the content.
    """
    pass  # native code

  def GetStatus(self):
    """
    Gets the status object

    :return: The status object.
    """
    pass  # native code


class DBM:
  """
  Polymorphic database manager.

  All operations except for Open and Close are thread-safe; Multiple threads can access the same database concurrently.  You can specify a data structure when you call the Open method.  Every opened database must be closed explicitly by the Close method to avoid data corruption.
  This class implements the iterable protocol so an instance is usable with "for-in" loop.
  """

  ANY_DATA = b"\x00[ANY]\x00"
  """The special bytes value for no-operation or any data."""

  def __init__(self):
    """
    Does nothing especially.
    """
    pass  # native code

  def __repr__(self):
    """
    Returns A string representation of the object.

    :return: The string representation of the object.
    """
    pass  # native code

  def __str__(self):
    """
    Returns A string representation of the content.

    :return: The string representation of the content.
    """
    pass  # native code

  def __len__(self):
    """
    Gets the number of records, to enable the len operator.

    :return: The number of records on success, or 0 on failure.
    """
    pass  # native code

  def __getitem__(self, key):
    """
    Gets the value of a record, to enable the [] operator.

    :param key: The key of the record.
    :return: The value of the matching record.  An exception is raised for missing records.  If the given key is a string, the returned value is also a string.  Otherwise, the return value is bytes.
    :raise StatusException: An exception containing the status object.
    """
    pass  # native code

  def __contains__(self, key):
    """
    Checks if a record exists or not, to enable the in operator.

    :param key: The key of the record.
    :return: True if the record exists, or False if not.  No exception is raised for missing records.
    """
    pass  # native code

  def __setitem__(self, key, value):
    """
    Sets a record of a key and a value, to enable the []= operator.

    :param key: The key of the record.
    :param value: The value of the record.
    :raise StatusException: An exception containing the status object.
    """
    pass  # native code

  def __delitem__(self, key):
    """
    Removes a record of a key, to enable the del [] operator.

    :param key: The key of the record.
    :raise StatusException: An exception containing the status object.
    """
    pass  # native code

  def __iter__(self):
    """
    Makes an iterator and initialize it, to comply to the iterator protocol.

    :return: The iterator for each record.
    """
    pass  # native code

  def Open(self, path, writable, **params):
    """
    Opens a database file.

    :param path: A path of the file.
    :param writable: If true, the file is writable.  If false, it is read-only.
    :param params: Optional keyword parameters.
    :return: The result status.

    The extension of the path indicates the type of the database.
      - .tkh : File hash database (HashDBM)
      - .tkt : File tree database (TreeDBM)
      - .tks : File skip database (SkipDBM)
      - .tkmt : On-memory hash database (TinyDBM)
      - .tkmb : On-memory tree database (BabyDBM)
      - .tkmc : On-memory cache database (CacheDBM)
      - .tksh : On-memory STL hash database (StdHashDBM)
      - .tkst : On-memory STL tree database (StdTreeDBM)

    The optional parameters can include an option for the concurrency tuning.  By default, database operatins are done under the GIL (Global Interpreter Lock), which means that database operations are not done concurrently even if you use multiple threads.  If the "concurrent" parameter is true, database operations are done outside the GIL, which means that database operations can be done concurrently if you use multiple threads.  However, the downside is that swapping thread data is costly so the actual throughput is often worse in the concurrent mode than in the normal mode.  Therefore, the concurrent mode should be used only if the database is huge and it can cause blocking of threads in multi-thread usage.

    The optional parameters can include options for the file opening operation.
      - truncate (bool): True to truncate the file.
      - no_create (bool): True to omit file creation.
      - no_wait (bool): True to fail if the file is locked by another process.
      - no_lock (bool): True to omit file locking.
      - sync_hard (bool): True to do physical synchronization when closing.

    The optional parameter "dbm" supercedes the decision of the database type by the extension.  The value is the type name: "HashDBM", "TreeDBM", "SkipDBM", "TinyDBM", "BabyDBM", "CacheDBM", "StdHashDBM", "StdTreeDBM".

    The optional parameter "file" specifies the internal file implementation class.  The default file class is "MemoryMapAtomicFile".  The other supported classes are "StdFile", "MemoryMapAtomicFile", "PositionalParallelFile", and "PositionalAtomicFile".

    For HashDBM, these optional parameters are supported.
      - update_mode (string): How to update the database file: "UPDATE_IN_PLACE" for the in-palce or "UPDATE_APPENDING" for the appending mode.
      - record_crc_mode (string): How to add the CRC data to the record: "RECORD_CRC_NONE" to add no CRC to each record, "RECORD_CRC_8" to add CRC-8 to each record, "RECORD_CRC_16" to add CRC-16 to each record, or "RECORD_CRC_32" to add CRC-32 to each record.
      - record_comp_mode (string): How to compress the record data: "RECORD_COMP_NONE" to do no compression, "RECORD_COMP_ZLIB" to compress with ZLib, "RECORD_COMP_ZSTD" to compress with ZStd, "RECORD_COMP_LZ4" to compress with LZ4, "RECORD_COMP_LZMA" to compress with LZMA, "RECORD_COMP_RC4" to cipher with RC4, "RECORD_COMP_AES" to cipher with AES.
      - offset_width (int): The width to represent the offset of records.
      - align_pow (int): The power to align records.
      - num_buckets (int): The number of buckets for hashing.
      - restore_mode (string): How to restore the database file: "RESTORE_SYNC" to restore to the last synchronized state, "RESTORE_READ_ONLY" to make the database read-only, or "RESTORE_NOOP" to do nothing.  By default, as many records as possible are restored.
      - fbp_capacity (int): The capacity of the free block pool.
      - min_read_size (int): The minimum reading size to read a record.
      - cache_buckets (bool): True to cache the hash buckets on memory.
      - cipher_key (string): The encryption key for cipher compressors.

    For TreeDBM, all optional parameters for HashDBM are available.  In addition, these optional parameters are supported.
      - max_page_size (int): The maximum size of a page.
      - max_branches (int): The maximum number of branches each inner node can have.
      - max_cached_pages (int): The maximum number of cached pages.
      - page_update_mode (string): What to do when each page is updated: "PAGE_UPDATE_NONE" is to do no operation or "PAGE_UPDATE_WRITE" is to write immediately.
      - key_comparator (string): The comparator of record keys: "LexicalKeyComparator" for the lexical order, "LexicalCaseKeyComparator" for the lexical order ignoring case, "DecimalKeyComparator" for the order of decimal integer numeric expressions, "HexadecimalKeyComparator" for the order of hexadecimal integer numeric expressions, "RealNumberKeyComparator" for the order of decimal real number expressions, and "FloatBigEndianKeyComparator" for the order of binary float-number expressions.

    For SkipDBM, these optional parameters are supported.
      - offset_width (int): The width to represent the offset of records.
      - step_unit (int): The step unit of the skip list.
      - max_level (int): The maximum level of the skip list.
      - restore_mode (string): How to restore the database file: "RESTORE_SYNC" to restore to the last synchronized state or "RESTORE_NOOP" to do nothing make the database read-only.  By default, as many records as possible are restored.
      - sort_mem_size (int): The memory size used for sorting to build the database in the at-random mode.
      - insert_in_order (bool): If true, records are assumed to be inserted in ascending order of the key.
      - max_cached_records (int): The maximum number of cached records.

    For TinyDBM, these optional parameters are supported.
      - num_buckets (int): The number of buckets for hashing.

    For BabyDBM, these optional parameters are supported.
      - key_comparator (string): The comparator of record keys. The same ones as TreeDBM.

    For CacheDBM, these optional parameters are supported.
      - cap_rec_num (int): The maximum number of records.
      - cap_mem_size (int): The total memory size to use.

    All databases support taking update logs into files.  It is enabled by setting the prefix of update log files.
      - ulog_prefix (str): The prefix of the update log files.
      - ulog_max_file_size (num): The maximum file size of each update log file.  By default, it is 1GiB.
      - ulog_server_id (num): The server ID attached to each log.  By default, it is 0.
      - ulog_dbm_index (num): The DBM index attached to each log.  By default, it is 0.

    For the file "PositionalParallelFile" and "PositionalAtomicFile", these optional parameters are supported.
      - block_size (int): The block size to which all blocks should be aligned.
      - access_options (str): Values separated by colon.  "direct" for direct I/O.  "sync" for synchrnizing I/O, "padding" for file size alignment by padding, "pagecache" for the mini page cache in the process.

    If the optional parameter "num_shards" is set, the database is sharded into multiple shard files.  Each file has a suffix like "-00003-of-00015".  If the value is 0, the number of shards is set by patterns of the existing files, or 1 if they doesn't exist.
    """
    pass  # native code

  def Close(self):
    """
    Closes the database file.

    :return: The result status.
    """
    pass  # native code

  def Process(self, key, func, writable):
    """
    Processes a record with an arbitrary function.

    :param key: The key of the record.
    :param func: The function to process a record.  The first parameter is the key of the record.  The second parameter is the value of the existing record, or None if it the record doesn't exist.  The return value is a string or bytes to update the record value.  If the return value is None, the record is not modified.  If the return value is False (not a false value but the False object), the record is removed.
    :param writable: True if the processor can edit the record.
    :return: The result status.

    This method is not available in the concurrent mode because the function cannot be invoked outside the GIL.
    """
    pass  # native code

  def Get(self, key, status=None):
    """
    Gets the value of a record of a key.

    :param key: The key of the record.
    :param status: A status object to which the result status is assigned.  It can be omitted.
    :return: The bytes value of the matching record or None on failure.
    """
    pass  # native code

  def GetStr(self, key, status=None):
    """
    Gets the value of a record of a key, as a string.

    :param key: The key of the record.
    :param status: A status object to which the result status is assigned.  It can be omitted.
    :return: The string value of the matching record or None on failure.
    """
    pass  # native code

  def GetMulti(self, *keys):
    """
    Gets the values of multiple records of keys.

    :param keys: The keys of records to retrieve.
    :return: A map of retrieved records.  Keys which don't match existing records are ignored.
    """
    pass  # native code

  def GetMultiStr(self, *keys):
    """
    Gets the values of multiple records of keys, as strings.

    :param keys: The keys of records to retrieve.
    :return: A map of retrieved records.  Keys which don't match existing records are ignored.
    """
    pass  # native code

  def Set(self, key, value, overwrite=True):
    """
    Sets a record of a key and a value.

    :param key: The key of the record.
    :param value: The value of the record.
    :param overwrite: Whether to overwrite the existing value.  It can be omitted and then false is set.
    :return: The result status.  If overwriting is abandoned, DUPLICATION_ERROR is returned.
    """
    pass  # native code

  def SetMulti(self, overwrite=True, **records):
    """
    Sets multiple records of the keyword arguments.

    :param overwrite: Whether to overwrite the existing value if there's a record with the same key.  If true, the existing value is overwritten by the new value.  If false, the operation is given up and an error status is returned.
    :param records: Records to store, specified as keyword parameters.
    :return: The result status.  If there are records avoiding overwriting, DUPLICATION_ERROR is returned.
    """
    pass  # native code

  def SetAndGet(self, key, value, overwrite=True):
    """
    Sets a record and get the old value.

    :param key: The key of the record.
    :param value: The value of the record.
    :param overwrite: Whether to overwrite the existing value if there's a record with the same key.  If true, the existing value is overwritten by the new value.  If false, the operation is given up and an error status is returned.
    :return: A pair of the result status and the old value.  If the record has not existed when inserting the new record, None is assigned as the value.  If not None, the type of the returned old value is the same as the parameter value.
    """
    pass  # native code

  def Remove(self, key):
    """
    Removes a record of a key.

    :param key: The key of the record.
    :return: The result status.  If there's no matching record, NOT_FOUND_ERROR is returned.
    """
    pass  # native code

  def RemoveMulti(self, keys):
    """
    Removes records of keys.

    :param key: The keys of the records.
    :return: The result status.  If there are missing records, NOT_FOUND_ERROR is returned.
    """
    pass  # native code

  def RemoveAndGet(self, key):
    """
    Removes a record and get the value.

    :param key: The key of the record.
    :return: A pair of the result status and the record value.  If the record does not exist, None is assigned as the value.  If not None, the type of the returned value is the same as the parameter key.
    """
    pass  # native code

  def Append(self, key, value, delim=""):
    """
    Appends data at the end of a record of a key.

    :param key: The key of the record.
    :param value: The value to append.
    :param delim: The delimiter to put after the existing record.
    :return: The result status.

    If there's no existing record, the value is set without the delimiter.
    """
    pass  # native code

  def AppendMulti(self, delim="", **records):
    """
    Appends data to multiple records of the keyword arguments.

    :param delim: The delimiter to put after the existing record.
    :param records: Records to append, specified as keyword parameters.
    :return: The result status.

    If there's no existing record, the value is set without the delimiter.
    """
    pass  # native code

  def CompareExchange(self, key, expected, desired):
    """
    Compares the value of a record and exchanges if the condition meets.

    :param key: The key of the record.
    :param expected: The expected value.  If it is None, no existing record is expected.  If it is ANY_DATA, an existing record with any value is expacted.
    :param desired: The desired value.  If it is None, the record is to be removed.  If it is ANY_DATA, no update is done.
    :return: The result status.  If the condition doesn't meet, INFEASIBLE_ERROR is returned.
    """
    pass  # native code

  def CompareExchangeAndGet(self, key, expected, desired):
    """
    Does compare-and-exchange and/or gets the old value of the record.

    :param key: The key of the record.
    :param expected: The expected value.  If it is None, no existing record is expected.  If it is ANY_DATA, an existing record with any value is expacted.
    :param desired: The desired value.  If it is None, the record is to be removed.  If it is ANY_DATA, no update is done.
    :return: A pair of the result status and the.old value of the record.  If the condition doesn't meet, the state is INFEASIBLE_ERROR.  If there's no existing record, the value is None.  If not None, the type of the returned old value is the same as the expected or desired value.
    """
    pass  # native code

  def Increment(self, key, inc=1, init=0, status=None):
    """
    Increments the numeric value of a record.

    :param key: The key of the record.
    :param inc: The incremental value.  If it is Utility.INT64MIN, the current value is not changed and a new record is not created.
    :param init: The initial value.
    :param status: A status object to which the result status is assigned.  It can be omitted.
    :return: The current value, or None on failure.

    The record value is stored as an 8-byte big-endian integer.  Negative is also supported.
    """
    pass  # native code

  def CompareExchangeMulti(self, expected, desired):
    """
    Compares the values of records and exchanges if the condition meets.

    :param expected: A sequence of pairs of the record keys and their expected values.  If the value is None, no existing record is expected.  If the value is ANY_DATA, an existing record with any value is expacted.
    :param desired: A sequence of pairs of the record keys and their desired values.  If the value is None, the record is to be removed.
    :return: The result status.  If the condition doesn't meet, INFEASIBLE_ERROR is returned.
    """
    pass  # native code

  def Rekey(old_key, new_key, overwrite=True, copying=False):
    """
    Changes the key of a record.

    :param old_key: The old key of the record.
    :param new_key: The new key of the record.
    :param overwrite: Whether to overwrite the existing record of the new key.
    :param copying: Whether to retain the record of the old key.

    :return: The result status.  If there's no matching record to the old key, NOT_FOUND_ERROR is returned.  If the overwrite flag is false and there is an existing record of the new key, DUPLICATION ERROR is returned.

    This method is done atomically.  The other threads observe that the record has either the old key or the new key.  No intermediate states are observed.
    """
    pass  # native code

  def PopFirst(self, status=None):
    """
    Gets the first record and removes it.

    :param status: A status object to which the result status is assigned.  It can be omitted.
    :return: A tuple of the bytes key and the bytes value of the first record.  On failure, None is returned.
    """
    pass  # native code

  def PopFirstStr(self, status=None):
    """
    Gets the first record as strings and removes it.

    :param status: A status object to which the result status is assigned.  It can be omitted.
    :return: A tuple of the string key and the string value of the first record.  On failure, None is returned.
    """
    pass  # native code

  def PushLast(self, value, wtime=None):
    """
    Adds a record with a key of the current timestamp.

    :param value: The value of the record.
    :param wtime: The current wall time used to generate the key.  If it is None, the system clock is used.
    :return: The result status.

    The key is generated as an 8-bite big-endian binary string of the timestamp.  If there is an existing record matching the generated key, the key is regenerated and the attempt is repeated until it succeeds.
    """
    pass  # native code

  def ProcessEach(self, func, writable):
    """
    Processes each and every record in the database with an arbitrary function.

    :param func: The function to process a record.  The first parameter is the key of the record.  The second parameter is the value of the existing record, or None if it the record doesn't exist.  The return value is a string or bytes to update the record value.  If the return value is None, the record is not modified.  If the return value is False (not a false value but the False object), the record is removed.
    :param writable: True if the processor can edit the record.
    :return: The result status.

    The given function is called repeatedly for each record.  It is also called once before the iteration and once after the iteration with both the key and the value being None.  This method is not available in the concurrent mode because the function cannot be invoked outside the GIL.
    """
    pass  # native code

  def Count(self):
    """
    Gets the number of records.

    :return: The number of records on success, or None on failure.
    """
    pass  # native code

  def GetFileSize(self):
    """
    Gets the current file size of the database.

    :return: The current file size of the database, or None on failure.
    """
    pass  # native code

  def GetFilePath(self):
    """
    Gets the path of the database file.

    :return: The file path of the database, or None on failure.
    """
    pass  # native code

  def GetTimestamp(self):
    """
    Gets the timestamp in seconds of the last modified time.

    :return: The timestamp of the last modified time, or None on failure.
    """
    pass  # native code

  def Clear(self):
    """
    Removes all records.

    :return: The result status.
    """
    pass  # native code

  def Rebuild(self, **params):
    """
    Rebuilds the entire database.

    :param params: Optional keyword parameters.
    :return: The result status.

    The optional parameters are the same as the Open method.  Omitted tuning parameters are kept the same or implicitly optimized.

    In addition, HashDBM, TreeDBM, and SkipDBM supports the following parameters.
      - skip_broken_records (bool): If true, the operation continues even if there are broken records which can be skipped.
      - sync_hard (bool): If true, physical synchronization with the hardware is done before finishing the rebuilt file.
    """
    pass  # native code

  def ShouldBeRebuilt(self):
    """
    Checks whether the database should be rebuilt.

    :return: True to be optimized or false with no necessity.
    """
    pass  # native code

  def Synchronize(self, hard, **params):
    """
    Synchronizes the content of the database to the file system.

    :param hard: True to do physical synchronization with the hardware or false to do only logical synchronization with the file system.
    :param params: Optional keyword parameters.
    :return: The result status.

    Only SkipDBM uses the optional parameters.  The "merge" parameter specifies paths of databases to merge, separated by colon.  The "reducer" parameter specifies the reducer to apply to records of the same key.  "ReduceToFirst", "ReduceToSecond", "ReduceToLast", etc are supported.
    """
    pass  # native code

  def CopyFileData(self, dest_path, sync_hard=False):
    """
    Copies the content of the database file to another file.

    :param dest_path: A path to the destination file.
    :param sync_hard: True to do physical synchronization with the hardware.
    :return: The result status.
    """
    pass  # native code

  def Export(self, dest_dbm):
    """
    Exports all records to another database.

    :param dest_dbm: The destination database.
    :return: The result status.
    """
    pass  # native code

  def ExportToFlatRecords(self, dest_file):
    """
    Exports all records of a database to a flat record file.

    :param dest_file: The file object to write records in.
    :return: The result status.

    A flat record file contains a sequence of binary records without any high level structure so it is useful as a intermediate file for data migration.
    """
    pass  # native code
    
  def ImportFromFlatRecords(self, src_file):
    """
    Imports records to a database from a flat record file.

    :param src_file: The file object to read records from.
    :return: The result status.
    """
    pass  # native code

  def ExportKeysAsLines(self, dest_file):
    """
    Exports the keys of all records as lines to a text file.

    :param dest_file: The file object to write keys in.
    :return: The result status.

    As the exported text file is smaller than the database file, scanning the text file by the search method is often faster than scanning the whole database.
    """
    pass  # native code

  def Inspect(self):
    """
    Inspects the database.

    :return: A map of property names and their values.
    """
    pass  # native code

  def IsOpen(self):
    """
    Checks whether the database is open.

    :return: True if the database is open, or false if not.
    """
    pass  # native code

  def IsWritable(self):
    """
    Checks whether the database is writable.

    :return: True if the database is writable, or false if not.
    """
    pass  # native code

  def IsHealthy(self):
    """
    Checks whether the database condition is healthy.

    :return: True if the database condition is healthy, or false if not.
    """
    pass  # native code

  def IsOrdered(self):
    """
    Checks whether ordered operations are supported.

    :return: True if ordered operations are supported, or false if not.
    """
    pass  # native code

  def Search(self, mode, pattern, capacity=0):
    """
    Searches the database and get keys which match a pattern.

    :param mode: The search mode.  "contain" extracts keys containing the pattern.  "begin" extracts keys beginning with the pattern.  "end" extracts keys ending with the pattern.  "regex" extracts keys partially matches the pattern of a regular expression.  "edit" extracts keys whose edit distance to the UTF-8 pattern is the least.  "editbin" extracts keys whose edit distance to the binary pattern is the least.  "containcase", "containword", and "containcaseword" extract keys considering case and word boundary.  Ordered databases support "upper" and "lower" which extract keys whose positions are upper/lower than the pattern. "upperinc" and "lowerinc" are their inclusive versions.
    :param pattern: The pattern for matching.
    :param capacity: The maximum records to obtain.  0 means unlimited.
    :return: A list of string keys matching the condition.
    """
    pass  # native code

  def MakeIterator(self):
    """
    Makes an iterator for each record.

    :return: The iterator for each record.
    """
    pass  # native code

  @classmethod
  def RestoreDatabase(cls, old_file_path, new_file_path, class_name="",
                      end_offset=-1, cipher_key=None):
    """
    Restores a broken database as a new healthy database.

    :param old_file_path: The path of the broken database.
    :param new_file_path: The path of the new database to be created.
    :param class_name: The name of the database class.  If it is None or empty, the class is guessed from the file extension.
    :param end_offset: The exclusive end offset of records to read.  Negative means unlimited.  0 means the size when the database is synched or closed properly.  Using a positive value is not meaningful if the number of shards is more than one.
    :param cipher_key: The encryption key for cipher compressors.  If it is None, an empty key is used.
    :return: The result status.
    """


class Iterator:
  """
  Iterator for each record.
  """

  def __init__(self, dbm):
    """
    Initializes the iterator.

    :param dbm: The database to scan.
    """
    pass  # native code

  def __repr__(self):
    """
    Returns A string representation of the object.

    :return: The string representation of the object.
    """
    pass  # native code

  def __str__(self):
    """
    Returns A string representation of the content.

    :return: The string representation of the content.
    """
    pass  # native code

  def __next__(self):
    """
    Moves the iterator to the next record, to comply to the iterator protocol.

    :return: A tuple of The key and the value of the current record.
    """
    pass  # native code

  def First(self):
    """
    Initializes the iterator to indicate the first record.

    :return: The result status.

    Even if there's no record, the operation doesn't fail.
    """
    pass  # native code

  def Last(self):
    """
    Initializes the iterator to indicate the last record.

    :return: The result status.

    Even if there's no record, the operation doesn't fail.  This method is suppoerted only by ordered databases.
    """
    pass  # native code

  def Jump(self, key):
    """
    Initializes the iterator to indicate a specific record.

    :param key: The key of the record to look for.
    :return: The result status.

    Ordered databases can support "lower bound" jump; If there's no record with the same key, the iterator refers to the first record whose key is greater than the given key.  The operation fails with unordered databases if there's no record with the same key.
    """
    pass  # native code

  def JumpLower(self, key, inclusive=False):
    """
    Initializes the iterator to indicate the last record whose key is lower than a given key.

    :param key: The key to compare with.
    :param inclusive: If true, the considtion is inclusive: equal to or lower than the key.
    :return: The result status.

    Even if there's no matching record, the operation doesn't fail.  This method is suppoerted only by ordered databases.
    """
    pass  # native code

  def JumpUpper(self, key, inclusive=False):
    """
    Initializes the iterator to indicate the first record whose key is upper than a given key.

    :param key: The key to compare with.
    :param inclusive: If true, the considtion is inclusive: equal to or upper than the key.
    :return: The result status.

    Even if there's no matching record, the operation doesn't fail.  This method is suppoerted only by ordered databases.
    """
    pass  # native code

  def Next(self):
    """
    Moves the iterator to the next record.

    :return: The result status.

    If the current record is missing, the operation fails.  Even if there's no next record, the operation doesn't fail.
    """
    pass  # native code

  def Previous(self):
    """
    Moves the iterator to the previous record.

    :return: The result status.

    If the current record is missing, the operation fails.  Even if there's no previous record, the operation doesn't fail.  This method is suppoerted only by ordered databases.
    """
    pass  # native code

  def Get(self, status=None):
    """
    Gets the key and the value of the current record of the iterator.

    :param status: A status object to which the result status is assigned.  It can be omitted.
    :return: A tuple of the bytes key and the bytes value of the current record.  On failure, None is returned.
    """
    pass  # native code

  def GetStr(self, status=None):
    """
    Gets the key and the value of the current record of the iterator, as strings.

    :param status: A status object to which the result status is assigned.  It can be omitted.
    :return: A tuple of the string key and the string value of the current record.  On failure, None is returned.
    """
    pass  # native code

  def GetKey(self, status=None):
    """
    Gets the key of the current record.

    :param status: A status object to which the result status is assigned.  It can be omitted.
    :return: The bytes key of the current record or None on failure.
    """
    pass  # native code

  def GetKeyStr(self, status=None):
    """
    Gets the key of the current record, as a string.

    :param status: A status object to which the result status is assigned.  It can be omitted.
    :return: The string key of the current record or None on failure.
    """
    pass  # native code

  def GetValue(self, status=None):
    """
    Gets the value of the current record.

    :param status: A status object to which the result status is assigned.  It can be omitted.
    :return: The bytes value of the current record or None on failure.
    """
    pass  # native code

  def GetValueStr(self, status=None):
    """
    Gets the value of the current record, as a string.

    :param status: A status object to which the result status is assigned.  It can be omitted.
    :return: The string value of the current record or None on failure.
    """
    pass  # native code

  def Set(self, value):
    """
    Sets the value of the current record.

    :param value: The value of the record.
    :return: The result status.
    """
    pass  # native code

  def Remove(self):
    """
    Removes the current record.

    :return: The result status.
    """
    pass  # native code

  def Step(self, status=None):
    """
    Gets the current record and moves the iterator to the next record.

    :param status: A status object to which the result status is assigned.  It can be omitted.
    :return: A tuple of the bytes key and the bytes value of the current record.  On failure, None is returned.
    """
    pass  # native code

  def StepStr(self, status=None):
    """
    Gets the current record and moves the iterator to the next record, as strings.

    :param status: A status object to which the result status is assigned.  It can be omitted.
    :return: A tuple of the string key and the string value of the current record.  On failure, None is returned.
    """
    pass  # native code


class AsyncDBM:
  """
  Asynchronous database manager adapter.

  This class is a wrapper of DBM for asynchronous operations.  A task queue with a thread pool is used inside.  Every method except for the constructor and the destructor is run by a thread in the thread pool and the result is set in the future oject of the return value.  The caller can ignore the future object if it is not necessary.  The Destruct method waits for all tasks to be done.  Therefore, the destructor should be called before the database is closed.
  """
  
  def __init__(self, dbm, num_worker_threads):
    """
    Sets up the task queue.

    :param dbm: A database object which has been opened.
    :param num_worker_threads: The number of threads in the internal thread pool.
    """
    pass  # native code

  def __repr__(self):
    """
    Returns A string representation of the object.

    :return: The string representation of the object.
    """
    pass  # native code

  def __str__(self):
    """
    Returns a string representation of the content.

    :return: The string representation of the content.
    """
    pass  # native code

  def Destruct():
    """
    Destructs the asynchronous database adapter.

    This method waits for all tasks to be done.
    """

  def Get(self, key):
    """
    Gets the value of a record of a key.

    :param key: The key of the record.
    :return: The future for the result status and the bytes value of the matching record.
    """
    pass  # native code

  def GetStr(self, key):
    """
    Gets the value of a record of a key, as a string.

    :param key: The key of the record.
    :return: The future for the result status and the string value of the matching record.
    """
    pass  # native code

  def GetMulti(self, *keys):
    """
    Gets the values of multiple records of keys.

    :param keys: The keys of records to retrieve.
    :return: The future for the result status and a map of retrieved records.  Keys which don't match existing records are ignored.
    """
    pass  # native code

  def GetMultiStr(self, *keys):
    """
    Gets the values of multiple records of keys, as strings.

    :param keys: The keys of records to retrieve.
    :return: The future for the result status and a map of retrieved records.  Keys which don't match existing records are ignored.
    """
    pass  # native code

  def Set(self, key, value, overwrite=True):
    """
    Sets a record of a key and a value.

    :param key: The key of the record.
    :param value: The value of the record.
    :param overwrite: Whether to overwrite the existing value.  It can be omitted and then false is set.
    :return: The future for the result status.  If overwriting is abandoned, DUPLICATION_ERROR is set.
    """
    pass  # native code

  def SetMulti(self, overwrite=True, **records):
    """
    Sets multiple records of the keyword arguments.

    :param overwrite: Whether to overwrite the existing value if there's a record with the same key.  If true, the existing value is overwritten by the new value.  If false, the operation is given up and an error status is returned.
    :param records: Records to store, specified as keyword parameters.
    :return: The future for the result status.  If overwriting is abandoned, DUPLICATION_ERROR is set.
    """
    pass  # native code

  def Append(self, key, value, delim=""):
    """
    Appends data at the end of a record of a key.

    :param key: The key of the record.
    :param value: The value to append.
    :param delim: The delimiter to put after the existing record.
    :return: The future for the result status.

    If there's no existing record, the value is set without the delimiter.
    """
    pass  # native code

  def AppendMulti(self, delim="", **records):
    """
    Appends data to multiple records of the keyword arguments.

    :param delim: The delimiter to put after the existing record.
    :param records: Records to append, specified as keyword parameters.
    :return: The future for the result status.

    If there's no existing record, the value is set without the delimiter.
    """
    pass  # native code

  def CompareExchange(self, key, expected, desired):
    """
    Compares the value of a record and exchanges if the condition meets.

    :param key: The key of the record.
    :param expected: The expected value.  If it is None, no existing record is expected.  If it is DBM.ANY_DATA, an existing record with any value is expacted.
    :param desired: The desired value.  If it is None, the record is to be removed.  If it is None, the record is to be removed.  If it is DBM.ANY_DATA, no update is done.
    :return: The future for the result status.  If the condition doesn't meet, INFEASIBLE_ERROR is set.
    """
    pass  # native code

  def Increment(self, key, inc=1, init=0):
    """
    Increments the numeric value of a record.

    :param key: The key of the record.
    :param inc: The incremental value.  If it is Utility.INT64MIN, the current value is not changed and a new record is not created.
    :param init: The initial value.
    :return: The future for the result status and the current value.

    The record value is stored as an 8-byte big-endian integer.  Negative is also supported.
    """
    pass  # native code

  def ProcessMulti(self, key_func_pairs, writable):
    """
    Processes multiple records with arbitrary functions.

    :param key_func_pairs: A list of pairs of keys and their functions.  The first parameter of the function is the key of the record.  The second parameter is the value of the existing record, or None if it the record doesn't exist.  The return value is a string or bytes to update the record value.  If the return value is None, the record is not modified.  If the return value is False (not a false value but the False object), the record is removed.
    :param writable: True if the processors can edit the record.
    :return: The result status.

    This method is not available in the concurrent mode because the function cannot be invoked outside the GIL.
    """
    pass  # native code

  def CompareExchangeMulti(self, expected, desired):
    """
    Compares the values of records and exchanges if the condition meets.

    :param expected: A sequence of pairs of the record keys and their expected values.  If the value is None, no existing record is expected.  If the value is DBM.ANY_DATA, an existing record with any value is expacted.
    :param desired: A sequence of pairs of the record keys and their desired values.  If the value is None, the record is to be removed.
    :return: The future for the result status.  If the condition doesn't meet, INFEASIBLE_ERROR is set.
    """
    pass  # native code

  def Rekey(old_key, new_key, overwrite=True, copying=False):
    """
    Changes the key of a record.

    :param old_key: The old key of the record.
    :param new_key: The new key of the record.
    :param overwrite: Whether to overwrite the existing record of the new key.
    :param copying: Whether to retain the record of the old key.

    :return: The future for the result status.  If there's no matching record to the old key, NOT_FOUND_ERROR is set.  If the overwrite flag is false and there is an existing record of the new key, DUPLICATION ERROR is set.

    This method is done atomically.  The other threads observe that the record has either the old key or the new key.  No intermediate states are observed.
    """
    pass  # native code

  def PopFirst(self):
    """
    Gets the first record and removes it.

    :return: The future for a tuple of the result status, the bytes key, and the bytes value of the first record.
    """
    pass  # native code

  def PopFirstStr(self):
    """
    Gets the first record as strings and removes it.

    :return: The future for a tuple of the result status, the string key, and the string value of the first record.
    """
    pass  # native code

  def PushLast(self, value, wtime=None):
    """
    Adds a record with a key of the current timestamp.

    :param value: The value of the record.
    :param wtime: The current wall time used to generate the key.  If it is None, the system clock is used.
    :return: The future for the result status.

    The key is generated as an 8-bite big-endian binary string of the timestamp.  If there is an existing record matching the generated key, the key is regenerated and the attempt is repeated until it succeeds.
    """
    pass  # native code

  def Clear(self):
    """
    Removes all records.

    :return: The future for the result status.
    """
    pass  # native code

  def Rebuild(self, **params):
    """
    Rebuilds the entire database.

    :param params: Optional keyword parameters.
    :return: The future for the result status.

    The parameters work in the same way as with DBM::Rebuild.
    """
    pass  # native code

  def Synchronize(self, hard, **params):
    """
    Synchronizes the content of the database to the file system.

    :param hard: True to do physical synchronization with the hardware or false to do only logical synchronization with the file system.
    :param params: Optional keyword parameters.
    :return: The future for the result status.

    The parameters work in the same way as with DBM::Synchronize.
    """
    pass  # native code

  def CopyFileData(self, dest_path, sync_hard=False):
    """
    Copies the content of the database file to another file.

    :param dest_path: A path to the destination file.
    :param sync_hard: True to do physical synchronization with the hardware.
    :return: The future for the result status.
    """
    pass  # native code

  def Export(self, dest_dbm):
    """
    Exports all records to another database.

    :param dest_dbm: The destination database.  The lefetime of the database object must last until the task finishes.
    :return: The future for the result status.
    """
    pass  # native code

  def ExportToFlatRecords(self, dest_file):
    """
    Exports all records of a database to a flat record file.

    :param dest_file: The file object to write records in.  The lefetime of the file object must last until the task finishes.
    :return: The future for the result status.

    A flat record file contains a sequence of binary records without any high level structure so it is useful as a intermediate file for data migration.
    """
    pass  # native code
    
  def ImportFromFlatRecords(self, src_file):
    """
    Imports records to a database from a flat record file.

    :param src_file: The file object to read records from.  The lefetime of the file object must last until the task finishes.
    :return: The future for the result status.
    """
    pass  # native code

  def Search(self, mode, pattern, capacity=0):
    """
    Searches the database and get keys which match a pattern.

    :param mode: The search mode.  "contain" extracts keys containing the pattern.  "begin" extracts keys beginning with the pattern.  "end" extracts keys ending with the pattern.  "regex" extracts keys partially matches the pattern of a regular expression.  "edit" extracts keys whose edit distance to the UTF-8 pattern is the least.  "editbin" extracts keys whose edit distance to the binary pattern is the least.
    :param pattern: The pattern for matching.
    :param capacity: The maximum records to obtain.  0 means unlimited.
    :return: The future for the result status and a list of keys matching the condition.
    """
    pass  # native code


class File:
  """
  Generic file implementation.

  All operations except for Open and Close are thread-safe; Multiple threads can access the same file concurrently.  You can specify a concrete class when you call the Open method.  Every opened file must be closed explicitly by the Close method to avoid data corruption.
  """

  def __init__(self):
    """
    Initializes the file object.
    """
    pass  # native code

  def __repr__(self):
    """
    Returns A string representation of the object.

    :return: The string representation of the object.
    """
    pass  # native code

  def __str__(self):
    """
    Returns A string representation of the content.

    :return: The string representation of the content.
    """
    pass  # native code

  def Open(self, path, writable, **params):
    """
    Opens a file.

    :param path: A path of the file.
    :param writable: If true, the file is writable.  If false, it is read-only.
    :param params: Optional keyword parameters.
    :return: The result status.

    The optional parameters can include an option for the concurrency tuning.  By default, database operatins are done under the GIL (Global Interpreter Lock), which means that database operations are not done concurrently even if you use multiple threads.  If the "concurrent" parameter is true, database operations are done outside the GIL, which means that database operations can be done concurrently if you use multiple threads.  However, the downside is that swapping thread data is costly so the actual throughput is often worse in the concurrent mode than in the normal mode.  Therefore, the concurrent mode should be used only if the database is huge and it can cause blocking of threads in multi-thread usage.

    The optional parameters can include options for the file opening operation.
      - truncate (bool): True to truncate the file.
      - no_create (bool): True to omit file creation.
      - no_wait (bool): True to fail if the file is locked by another process.
      - no_lock (bool): True to omit file locking.
      - sync_hard (bool): True to do physical synchronization when closing.

    The optional parameter "file" specifies the internal file implementation class.  The default file class is "MemoryMapAtomicFile".  The other supported classes are "StdFile", "MemoryMapAtomicFile", "PositionalParallelFile", and "PositionalAtomicFile".

    For the file "PositionalParallelFile" and "PositionalAtomicFile", these optional parameters are supported.
      - block_size (int): The block size to which all blocks should be aligned.
      - access_options (str): Values separated by colon.  "direct" for direct I/O.  "sync" for synchrnizing I/O, "padding" for file size alignment by padding, "pagecache" for the mini page cache in the process.
    """
    pass  # native code

  def Close(self):
    """
    Closes the file.

    :return: The result status.
    """
    pass  # native code

  def Read(self, off, size, status=None):
    """
    Reads data.
    
    :param off: The offset of a source region.
    :param size: The size to be read.
    :param status: A status object to which the result status is assigned.  It can be omitted.
    :return: The bytes value of the read data or None on failure.
    """
    pass  # native code

  def ReadStr(self, off, size, status=None):
    """
    Reads data as a string.
    
    :param off: The offset of a source region.
    :param size: The size to be read.
    :param status: A status object to which the result status is assigned.  It can be omitted.
    :return: The string value of the read data or None on failure.
    """
    pass  # native code

  def Write(self, off, data):
    """
    Writes data.

    :param off: The offset of the destination region.
    :param data: The data to write.
    :return: The result status.
    """
    pass  # native code

  def Append(self, data, status=None):
    """
    Appends data at the end of the file.

    :param data: The data to write.
    :param status: A status object to which the result status is assigned.  It can be omitted.
    :return: The offset at which the data has been put, or None on failure.
    """
    pass  # native code

  def Truncate(self, size):
    """
    Truncates the file.

    :param size: The new size of the file.
    :return: The result status.

    If the file is shrunk, data after the new file end is discarded.  If the file is expanded, null codes are filled after the old file end.
    """
    pass  # native code

  def Synchronize(self, hard, off=0, size=0):
    """
    Synchronizes the content of the file to the file system.

    :param hard: True to do physical synchronization with the hardware or false to do only logical synchronization with the file system.
    :param off: The offset of the region to be synchronized.
    :param size: The size of the region to be synchronized.  If it is zero, the length to the end of file is specified.
    :return: The result status.

    The pysical file size can be larger than the logical size in order to improve performance by reducing frequency of allocation.  Thus, you should call this function before accessing the file with external tools.
    """
    pass  # native code

  def GetSize(self):
    """
    Gets the size of the file.

    :return: The size of the file or None on failure.
    """
    pass  # native code

  def GetPath(self):
    """
    Gets the path of the file.

    :return: The path of the file or None on failure.
    """
    pass  # native code

  def Search(self, mode, pattern, capacity=0):
    """
    Searches the file and get lines which match a pattern.

    :param mode: The search mode.  "contain" extracts lines containing the pattern.  "begin" extracts lines beginning with the pattern.  "end" extracts lines ending with the pattern.  "regex" extracts lines partially matches the pattern of a regular expression.  "edit" extracts lines whose edit distance to the UTF-8 pattern is the least.  "editbin" extracts lines whose edit distance to the binary pattern is the least.
    :param pattern: The pattern for matching.
    :param capacity: The maximum records to obtain.  0 means unlimited.
    :return: A list of lines matching the condition.
    """
    pass  # native code


class Index:
  """
  Secondary index interface.

  All operations except for Open and Close are thread-safe; Multiple threads can access the same index concurrently.  You can specify a data structure when you call the Open method.  Every opened index must be closed explicitly by the Close method to avoid data corruption.
  This class implements the iterable protocol so an instance is usable with "for-in" loop.
  """

  def __repr__(self):
    """
    Returns a string representation of the object.

    :return: The string representation of the object.
    """
    pass  # native code

  def __str__(self):
    """
    Returns a string representation of the content.

    :return: The string representation of the content.
    """
    pass  # native code

  def __len__(self):
    """
    Gets the number of records, to enable the len operator.

    :return: The number of records on success, or 0 on failure.
    """
    pass  # native code

  def __contains__(self, record):
    """
    Checks if a record exists or not, to enable the in operator.

    :param record: A tuple of the key and the value to check.
    :return: True if the record exists, or False if not.  No exception is raised for missing records.
    """
    pass  # native code

  def __iter__(self):
    """
    Makes an iterator and initialize it, to comply to the iterator protocol.

    :return: The iterator for each record.
    """
    pass  # native code
  
  def Open(self, path, writable, **params):
    """
    Opens an index file.

    :param path: A path of the file.
    :param writable: If true, the file is writable.  If false, it is read-only.
    :param params: Optional keyword parameters.
    :return: The result status.

    If the path is empty, BabyDBM is used internally, which is equivalent to using the MemIndex class.  If the path ends with ".tkt", TreeDBM is used internally, which is equivalent to using the FileIndex class.  If the key comparator of the tuning parameter is not set, PairLexicalKeyComparator is set implicitly.  Other compatible key comparators are PairLexicalCaseKeyComparator, PairDecimalKeyComparator, PairHexadecimalKeyComparator, PairRealNumberKeyComparator, and PairFloatBigEndianKeyComparator.  Other options can be specified as with DBM::Open.
    """
    pass  # native code

  def Close(self):
    """
    Closes the index file.

    :return: The result status.
    """
    pass  # native code

  def GetValues(self, key, max=0):
    """
    Gets all values of records of a key.
    :param key: The key to look for.
    :param max: The maximum number of values to get.  0 means unlimited.
    :return: A list of all values of the key.  An empty list is returned on failure.
    """
    pass  # native code

  def GetValuesStr(self, key, max=0):
    """
    Gets all values of records of a key, as strings.
    :param key: The key to look for.
    :param max: The maximum number of values to get.  0 means unlimited.
    :return: A list of all values of the key.  An empty list is returned on failure.
    """
    pass  # native code

  def Add(self, key, value):
    """
    Adds a record.

    :param key: The key of the record.  This can be an arbitrary expression to search the index.
    :param value: The value of the record.  This should be a primary value of another database.
    :return: The result status.
    """
    pass  # native code

  def Remove(self, key, value):
    """
    Removes a record.

    :param key: The key of the record.
    :param value: The value of the record.
    :return: The result status.
    """
    pass  # native code

  def Count(self):
    """
    Gets the number of records.

    :return: The number of records, or 0 on failure.
    """
    pass  # native code

  def GetFilePath(self):
    """
    Gets the path of the index file.
    :return: The file path of the index, or an empty string on failure.
    """
    pass  # native code

  def Clear(self):
    """
    Removes all records.

    :return: The result status.
    """
    pass  # native code

  def Rebuild(self):
    """
    Rebuilds the entire index.

    :return: The result status.
    """
    pass  # native code

  def Synchronize(self, hard):
    """
    Synchronizes the content of the index to the file system.

    :param hard: True to do physical synchronization with the hardware or false to do only logical synchronization with the file system.
    :return: The result status.
    """
    pass  # native code

  def IsOpen(self):
    """
    Checks whether the index is open.

    :return: True if the index is open, or false if not.
    """
    pass  # native code

  def IsWritable(self):
    """
    Checks whether the index is writable.

    :return: True if the index is writable, or false if not.
    """

  def MakeIterator(self):
    """
    Makes an iterator for each record.

    :return: The iterator for each record.
    """
    pass  # native code


class IndexIterator:
  """
  Iterator for each record of the secondary index.
  """

  def __init__(self, index):
    """
    Initializes the iterator.

    :param index: The index to scan.
    """
    pass  # native code

  def __repr__(self):
    """
    Returns A string representation of the object.

    :return: The string representation of the object.
    """
    pass  # native code

  def __str__(self):
    """
    Returns A string representation of the content.

    :return: The string representation of the content.
    """
    pass  # native code

  def __next__(self):
    """
    Moves the iterator to the next record, to comply to the iterator protocol.

    :return: A tuple of The key and the value of the current record.
    """
    pass  # native code

  def First(self):
    """
    Initializes the iterator to indicate the first record.
    """
    pass  # native code

  def Last(self):
    """
    Initializes the iterator to indicate the last record.
    """
    pass  # native code

  def Jump(self, key, value=""):
    """
    Initializes the iterator to indicate a specific range.

    :param key: The key of the lower bound.
    :param value: The value of the lower bound.
    """
    pass  # native code

  def Next(self):
    """
    Moves the iterator to the next record.
    """
    pass  # native code

  def Previous(self):
    """
    Moves the iterator to the previous record.
    """
    pass  # native code

  def Get(self):
    """
    Gets the key and the value of the current record of the iterator.

    :return: A tuple of the bytes key and the bytes value of the current record.  On failure, None is returned.
    """
    pass  # native code

  def GetStr(self):
    """
    Gets the key and the value of the current record of the iterator, as strings.

    :return: A tuple of the string key and the string value of the current record.  On failure, None is returned.
    """
    pass  # native code


# END OF FILE