34 wxASSERT( wxThread::IsMain() );
38 for(
const auto& [node, version] : aPartition.
identity )
42 if( std::holds_alternative<NAME_KEY>( nodeKey ) && version == 0 )
45 const auto* key = std::get_if<RECORD_NODE>( &nodeKey );
46 const auto* entry = key ? aRecords.
Find( key->record ) :
nullptr;
49 throw std::invalid_argument(
"Bundle partition does not match current records" );
54 result.items.push_back( { item, key->record.inst } );
61 result.claims.push_back( { key->record, claim, {}, &claim == &record.
claims.front() } );
67 result.netclasses.erase( std::ranges::unique(
result.netclasses ).begin(),
result.netclasses.end() );
69 if(
result.claims.empty() )
76 const auto& leaves =
source.claim.schema->leaves;
79 if( !leaves.empty() && !std::in_range<uint32_t>( leaves.size() - 1 ) )
80 throw std::length_error(
"Bus schema exceeds slot ordinal range" );
82 source.leaves.reserve( leaves.size() );
88 for(
const wxString&
group : leaf.groupPath )
91 local += leaf.localName;
106 if( aInput.
claims.empty() )
112 throw std::invalid_argument(
"Bundle binding requires a parent and canonical schema" );
132 for(
size_t i = 0; i < canonical.
leaves.size(); ++i )
135 result.members.push_back( key );
136 result.slots.push_back( makeSlot( key, canonical, i ) );
140 std::map<std::pair<INST_ID, NAME_ID>,
const BUNDLE_CLAIM*> answers;
147 const auto [found, inserted] = answers.try_emplace( {
source.record.inst,
source.claim.name }, &
source );
149 if( !inserted && claimLess( found->second->claim,
source.claim ) )
155 if( !
source.claim.schema ||
source.leaves.size() !=
source.claim.schema->leaves.size() )
156 throw std::invalid_argument(
"Prepared bundle leaves do not match their schema" );
161 if( sheetPin &&
source.claim.portInstance )
163 if(
auto found = answers.find( { *source.claim.portInstance, source.claim.name } ); found != answers.end() )
164 answer = found->second;
168 const bool named = !sheetPin ||
source.drivesRecord;
171 if( !named && !answer )
175 const auto parentEdges = [&](
SLOT_INPUT& aSlot ) -> std::vector<NAME_KEY>&
177 return sheetPin ? aSlot.parentEdges : aSlot.edges;
182 for(
const auto& [from, to] : alignment.
matched )
184 parentEdges(
result.slots[to] )
185 .push_back( { SCOPE::SHEET,
source.record.inst,
source.leaves[from].name } );
192 const auto ordinal =
static_cast<uint32_t
>( from );
196 parentEdges( slot ).push_back( { SCOPE::SHEET,
source.record.inst,
source.leaves[from].name } );
201 result.slots.push_back( std::move( slot ) );
211 std::ranges::sort( *edges, keyLess );
212 edges->erase( std::ranges::unique( *edges ).begin(), edges->end() );
227 wxASSERT( wxThread::IsMain() );
230 std::set<SLOT_KEY, KEY_LESS> live(
m_slots.Entries().key_comp() );
231 std::set<NODE_ID> parents;
233 for(
const auto& bundle : aBundles.
Entries() )
235 const NODE_ID parent = bundle->input.anchor;
237 if( !parents.insert( parent ).second )
238 throw std::invalid_argument(
"Duplicate bundle component" );
240 const auto [previous, inserted] =
m_bundleInputs.try_emplace( parent, bundle->version );
241 const bool changed = inserted || std::exchange( previous->second, bundle->version ) != bundle->version;
243 for(
const SLOT_INPUT& slot : bundle->value.slots )
246 throw std::invalid_argument(
"Slot has a duplicate key or inconsistent parent" );
253 for(
auto it =
m_slots.Entries().begin(); it !=
m_slots.Entries().end(); )
256 const SLOT_KEY key = ( it++ )->first;
258 if( !live.contains( key ) )
263 [&](
const auto& entry )
265 return !parents.contains( entry.first );
286 std::set<NODE_ID> claimedNames;
289 claimedNames.insert( record.edges.begin(), record.edges.end() );
291 for(
const auto& [key, entry] : aSlots.
Entries() )
294 input.
edges.reserve( entry->value.edges.size() );
296 for(
const NAME_KEY& edge : entry->value.edges )
297 input.edges.push_back( aKeys.
InternNode( edge ) );
300 for(
const NAME_KEY& edge : entry->value.parentEdges )
302 if(
const NODE_ID node = aKeys.
InternNode( edge ); claimedNames.contains( node ) )
303 input.edges.push_back( node );
306 result.push_back( std::move( input ) );
const auto & Entries() const
const ENTRY * Find(const KEY &aKey) const
Entry references survive unchanged writes, but not replacement or erasure of their key.
One sequence for all cache tables for the lifetime of an engine session.
Cache current component evaluations by exact node/version identity, within one stratum and key sessio...
const auto & Entries() const
CACHE_TABLE< RECORD_KEY, ISLAND_RECORD, KEY_LESS > RECORD_CACHE
Session IDs are dense handles, never a canonical ordering.
const NODE_KEY & Node(NODE_ID aId) const
const wxString & Name(NAME_ID aId) const
NAME_ID InternName(const wxString &aText)
NODE_ID InternNode(NODE_KEY aKey)
CACHE_TABLE< SLOT_KEY, SLOT_INPUT, KEY_LESS > SLOT_CACHE
std::map< NODE_ID, uint64_t > m_bundleInputs
void Update(const COMPONENT_CACHE< BUNDLE_BINDING > &aBundles)
SLOT_STORE(CACHE_VERSIONS &aVersions, SESSION_KEYS &aKeys)
Value keys and the key session of the schematic connectivity engine.
std::variant< RECORD_NODE, NAME_KEY, SLOT_KEY > NODE_KEY
Any node of the union-find graph.
std::ranges::iterator_t< RANGE > SelectDriver(RANGE &aClaims, const CLAIM_LESS &aLess, PROJ aProj={})
The driver of aClaims.
BUNDLE_INPUT PrepareBundle(const PARTITION &aPartition, const RECORD_STORE::RECORD_CACHE &aRecords, SESSION_KEYS &aKeys)
Collect the bus claims of a bundle partition and intern their leaf names on the main thread.
uint32_t NODE_ID
Session handle of a NODE_KEY graph node.
BUS_ALIGNMENT Align(const BUS_SCHEMA &aLeft, const BUS_SCHEMA &aRight)
Match the leaves of aLeft to the leaves of aRight.
constexpr uint32_t INVALID_ID
Marks an unset handle.
BUNDLE_BINDING BindBundle(const BUNDLE_INPUT &aInput, const SESSION_KEYS &aKeys)
Align the prepared claims to the canonical claim and make the member slots.
std::vector< NODE_INPUT > SignalNodes(const RECORD_STORE::RECORD_CACHE &aRecords, const SLOT_STORE::SLOT_CACHE &aSlots, SESSION_KEYS &aKeys)
Main-thread interning of current signal records and slots for the signal fold.
@ SHEET_PIN
Sheet pin. The name belongs to the child instance.
@ BUS_MEMBER
Synthetic claim of a bus member slot, set by BindBundle().
@ HIER_LABEL
Hierarchical label. The first strong priority.
std::vector< NODE_INPUT > RecordNodes(const RECORD_STORE::RECORD_CACHE &aRecords, KIND aKind, SESSION_KEYS &aKeys)
Main-thread node interning for one record stratum.
Bound result of one bus component.
NAME_ID fullName
Leaf name after the sheet path of this claim.
NAME_ID localName
Group path and leaf local name joined with dots.
NAME_ID name
Leaf name with all group prefixes.
One bus claim of a bundle partition, with its leaf names interned.
std::vector< LEAF_NAME > leaves
One entry for each leaf of the claim schema, in the same order.
RECORD_KEY record
Record of the island that holds the claim.
Member correspondence between two bus schemas.
std::vector< size_t > unmappedLeft
Left leaf ordinals without a right partner.
std::vector< std::pair< size_t, size_t > > matched
Pairs of left and right leaf ordinals.
Strict weak order on claims by value.
The claim of one item for the name of its island.
ITEM_KEY source
The claiming item, the last tie-break.
uint16_t depth
Sheet path size, or zero if unscoped.
NAME_ID ncName
Name of an unconnected pin net.
NAME_ID name
Item text without the sheet prefix.
std::shared_ptr< const BUS_SCHEMA > schema
Parsed bus, or null for a signal.
NAME_ID path
Sheet prefix, or the empty name if unscoped.
NAME_ID fullName
path followed by name.
std::vector< NAME_ID > netclasses
std::vector< KIID > items
std::vector< CLAIM > claims
front() is the SelectDriver() result, the rest descend by CLAIM_LESS.
Orders keys by value through SESSION_KEYS::Less().
The graph node of one name in one scope.
Orders name handles by UTF-8 value.
Exact identity of one connected component.
std::vector< std::pair< NODE_ID, uint64_t > > identity
INST_ID inst
The sheet instance of the record.
One member position of a bus.
wxString result
Test unit parsing edge cases and error handling.