threads_table.rs

Overview

This file defines a data structure and associated operations for managing a mapping between account routing keys and thread identifiers, encapsulated in a ThreadsTable. It provides functionality to merge thread tables, list threads, and perform bit-level operations on routing keys. The core concept revolves around the AccountRouting struct, which combines a decentralized application identifier (DAppIdentifier) and an account address (AccountAddress) to serve as a key in the thread table. The ThreadsTable itself is a specialized instance of a generic bitmask table keyed by AccountRouting and indexed by ThreadIdentifier.

Key Components

AccountRouting

pub struct AccountRouting(pub DAppIdentifier, pub AccountAddress);

A composite key type used for routing accounts to threads. It consists of:

Traits and Implementations

Usage Example

let dapp_id = DAppIdentifier::default();
let account_addr = AccountAddress::default();
let routing = AccountRouting(dapp_id.clone(), account_addr.clone());

// Access bits
let bit = routing.get_bit_value(10);
routing.set_bit_value(10, true);

// Debug output
println!("{:?}", routing);

ThreadsTable

pub type ThreadsTable = crate::bitmask::table::BitmasksTable<AccountRouting, ThreadIdentifier>;

An alias for a bitmask table mapping AccountRouting keys to ThreadIdentifier values.

Methods

Usage Example

let mut table1 = ThreadsTable::new();
let mut table2 = ThreadsTable::new();
// Insert rows into table1 and table2...

table1.merge(&table2)?; // Merge tables

for thread in table1.list_threads() {
    println!("Thread: {:?}", thread);
}

println!("Number of rows: {}", table1.length());

Implementation Details and Algorithms

Interactions with Other Components

Test Module

The file contains a comprehensive test module verifying serialization, merging behavior, and duplicate handling in ThreadsTable.

Helper function add_mask facilitates creating and inserting Bitmask rows into the table for testing.

Mermaid Diagram

classDiagram
class AccountRouting {
+DAppIdentifier
+AccountAddress
+bitand()
+get_bit_value()
+set_bit_value()
}
class ThreadsTable {
+merge()
+list_threads()
+length()
}
AccountRouting <|-- ThreadsTable : uses as key
ThreadsTable ..> ThreadIdentifier : maps to

This diagram shows the relationship where ThreadsTable is a bitmask table keyed by AccountRouting and mapping to ThreadIdentifier. The AccountRouting class provides bitwise and bit-level operations used by the table.