Package tkrzw
Class Index
Object
Index
Secondary index interface.
- Note:
- All operations except for "open" and "close" are thread-safe; Multiple threads can access the same dindex 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.
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionadd
(byte[] key, byte[] value) Adds a record.Adds a record, with string data.clear()
Removes all records.close()
Closes the index file.boolean
contains
(byte[] key, byte[] value) Checks if a record exists or not.boolean
Checks if a record exists or not, with string data.long
count()
Gets the number of records.void
destruct()
Destructs the object and releases resources.Gets the path of the index file.byte[][]
getValues
(byte[] key, int max) Gets all values of records of a key.String[]
Gets all values of records of a key, with string data.boolean
isOpen()
Checks whether the index is open.boolean
Checks whether the index is writable.Makes an iterator for each record.Opens an index file, without optional parameters.Opens an index file, with a string expression for optional parameters.Opens an index file.rebuild()
Rebuilds the entire index.remove
(byte[] key, byte[] value) Removes a record.Removes a record, with string data.synchronize
(boolean hard) Synchronizes the content of the index to the file system.toString()
Gets a string representation of the index.
-
Constructor Details
-
Index
public Index()Constructor.
-
-
Method Details
-
destruct
public void destruct()Destructs the object and releases resources.- Note:
- The index is closed implicitly if it has not been closed. As long as you close the index explicitly, you don't have to call this method.
-
open
Opens an index file.- Parameters:
path
- A path of the file.writable
- If true, the file is writable. If false, it is read-only.params
- Optional parameters. If it is null, it is ignored.- Returns:
- The result status.
- Note:
- 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, PairSignedBigEndianKeyComparator, and PairFloatBigEndianKeyComparator. Other options can be specified as with DBM::open.
-
open
Opens an index file, with a string expression for optional parameters.- Parameters:
path
- A path of the file.writable
- If true, the file is writable. If false, it is read-only.params
- The optional parameter expression in "key=value,key=value" format.- Returns:
- The result status.
-
open
Opens an index file, without optional parameters.- Parameters:
path
- A path of the file.writable
- If true, the file is writable. If false, it is read-only.- Returns:
- The result status.
-
close
Closes the index file.- Returns:
- The result status.
-
contains
public boolean contains(byte[] key, byte[] value) Checks if a record exists or not.- Parameters:
key
- The key of the record.value
- The key of the record.- Returns:
- True if the record exists, or false if not.
-
contains
Checks if a record exists or not, with string data.- Parameters:
key
- The key of the record.value
- The key of the record.- Returns:
- True if the record exists, or false if not.
-
getValues
public byte[][] getValues(byte[] key, int max) Gets all values of records of a key.- Parameters:
key
- The key to look for.max
- The maximum number of values to get. 0 means unlimited.- Returns:
- All values of the key. An empty array is returned on failure.
-
getValues
Gets all values of records of a key, with string data.- Parameters:
key
- The key to look for.max
- The maximum number of values to get. 0 means unlimited.- Returns:
- All values of the key. An empty array is returned on failure.
-
add
Adds a record.- Parameters:
key
- The key of the record. This can be an arbitrary expression to search the index.value
- The value of the record. This should be a primary value of another database.- Returns:
- The result status.
-
add
Adds a record, with string data.- Parameters:
key
- The key of the record. This can be an arbitrary expression to search the index.value
- The value of the record. This should be a primary value of another database.- Returns:
- The result status.
-
remove
Removes a record.- Parameters:
key
- The key of the record.value
- The value of the record.- Returns:
- The result status.
-
remove
Removes a record, with string data.- Parameters:
key
- The key of the record.value
- The value of the record.- Returns:
- The result status.
-
count
public long count()Gets the number of records.- Returns:
- The number of records, or -1 on failure.
-
getFilePath
Gets the path of the index file.- Returns:
- The file path of the index, or an empty string on failure.
-
clear
Removes all records.- Returns:
- The result status.
-
rebuild
Rebuilds the entire index.- Returns:
- The result status.
-
synchronize
Synchronizes the content of the index to the file system.- Parameters:
hard
- True to do physical synchronization with the hardware or false to do only logical synchronization with the file system.- Returns:
- The result status.
-
isOpen
public boolean isOpen()Checks whether the index is open.- Returns:
- True if the index is open, or false if not.
-
isWritable
public boolean isWritable()Checks whether the index is writable.- Returns:
- True if the index is writable, or false if not.
-
makeIterator
Makes an iterator for each record.- Returns:
- The iterator for each record.
- Note:
- Every iterator should be destructed explicitly by the "destruct" method.
-
toString
Gets a string representation of the index.
-