@@ -232,6 +232,7 @@ class _CConfig(Structure):
232232 ("log_level" , c_int ),
233233 ("block_cache_size" , c_size_t ),
234234 ("max_open_sstables" , c_size_t ),
235+ ("max_memory_usage" , c_size_t ),
235236 ("log_to_file" , c_int ),
236237 ("log_truncation_at" , c_size_t ),
237238 ]
@@ -444,6 +445,12 @@ class _CCacheStats(Structure):
444445_lib .tidesdb_register_comparator .argtypes = [c_void_p , c_char_p , COMPARATOR_FUNC , c_void_p , DESTROY_FUNC ]
445446_lib .tidesdb_register_comparator .restype = c_int
446447
448+ _lib .tidesdb_get_comparator .argtypes = [c_void_p , c_char_p , POINTER (COMPARATOR_FUNC ), POINTER (c_void_p )]
449+ _lib .tidesdb_get_comparator .restype = c_int
450+
451+ _lib .tidesdb_delete_column_family .argtypes = [c_void_p , c_void_p ]
452+ _lib .tidesdb_delete_column_family .restype = c_int
453+
447454
448455@dataclass
449456class Config :
@@ -455,6 +462,7 @@ class Config:
455462 log_level : LogLevel = LogLevel .LOG_INFO
456463 block_cache_size : int = 64 * 1024 * 1024
457464 max_open_sstables : int = 256
465+ max_memory_usage : int = 0
458466 log_to_file : bool = False
459467 log_truncation_at : int = 24 * 1024 * 1024
460468
@@ -1230,6 +1238,7 @@ def __init__(self, config: Config) -> None:
12301238 log_level = int (config .log_level ),
12311239 block_cache_size = config .block_cache_size ,
12321240 max_open_sstables = config .max_open_sstables ,
1241+ max_memory_usage = config .max_memory_usage ,
12331242 log_to_file = 1 if config .log_to_file else 0 ,
12341243 log_truncation_at = config .log_truncation_at ,
12351244 )
@@ -1251,6 +1260,7 @@ def open(
12511260 log_level : LogLevel = LogLevel .LOG_INFO ,
12521261 block_cache_size : int = 64 * 1024 * 1024 ,
12531262 max_open_sstables : int = 256 ,
1263+ max_memory_usage : int = 0 ,
12541264 log_to_file : bool = False ,
12551265 log_truncation_at : int = 24 * 1024 * 1024 ,
12561266 ) -> TidesDB :
@@ -1264,6 +1274,7 @@ def open(
12641274 log_level: Logging level
12651275 block_cache_size: Size of block cache in bytes
12661276 max_open_sstables: Maximum number of open SSTables
1277+ max_memory_usage: Global memory limit in bytes (0 = auto, 50% of system RAM)
12671278 log_to_file: Write logs to file instead of stderr
12681279 log_truncation_at: Log file truncation size in bytes (0 = no truncation)
12691280
@@ -1277,6 +1288,7 @@ def open(
12771288 log_level = log_level ,
12781289 block_cache_size = block_cache_size ,
12791290 max_open_sstables = max_open_sstables ,
1291+ max_memory_usage = max_memory_usage ,
12801292 log_to_file = log_to_file ,
12811293 log_truncation_at = log_truncation_at ,
12821294 )
@@ -1599,11 +1611,51 @@ def c_comparator(key1_ptr, key1_size, key2_ptr, key2_size, ctx_ptr):
15991611 self ._comparator_refs .append (c_func )
16001612
16011613 result = _lib .tidesdb_register_comparator (
1602- self ._db , name .encode ("utf-8" ), c_func , None , None
1614+ self ._db , name .encode ("utf-8" ), c_func , c_void_p ( None ), DESTROY_FUNC ()
16031615 )
16041616 if result != TDB_SUCCESS :
16051617 raise TidesDBError .from_code (result , "failed to register comparator" )
16061618
1619+ def get_comparator (self , name : str ) -> bool :
1620+ """
1621+ Check if a comparator is registered by name.
1622+
1623+ Args:
1624+ name: Name of the comparator to look up
1625+
1626+ Returns:
1627+ True if the comparator is registered, False otherwise
1628+ """
1629+ if self ._closed :
1630+ raise TidesDBError ("Database is closed" )
1631+
1632+ fn = COMPARATOR_FUNC ()
1633+ ctx = c_void_p ()
1634+ result = _lib .tidesdb_get_comparator (
1635+ self ._db , name .encode ("utf-8" ), ctypes .byref (fn ), ctypes .byref (ctx )
1636+ )
1637+ return result == TDB_SUCCESS
1638+
1639+ def delete_column_family (self , cf : ColumnFamily ) -> None :
1640+ """
1641+ Delete a column family by pointer (skips name lookup).
1642+
1643+ This is faster than drop_column_family() when you already hold a
1644+ ColumnFamily handle, as it avoids a redundant linear scan by name.
1645+
1646+ Args:
1647+ cf: Column family handle to delete
1648+
1649+ Raises:
1650+ TidesDBError: If deletion fails
1651+ """
1652+ if self ._closed :
1653+ raise TidesDBError ("Database is closed" )
1654+
1655+ result = _lib .tidesdb_delete_column_family (self ._db , cf ._cf )
1656+ if result != TDB_SUCCESS :
1657+ raise TidesDBError .from_code (result , "failed to delete column family" )
1658+
16071659 def __enter__ (self ) -> TidesDB :
16081660 return self
16091661
0 commit comments