From 4175f0971d1ee76f52b46e0a198cd60bc9bb411a Mon Sep 17 00:00:00 2001 From: Bruce Mitchener Date: Wed, 18 Feb 2026 09:37:25 +0700 Subject: [PATCH] attributed_text: clarify attribute query scan complexity docs Document that both `attributes_at` and `attributes_for_range` perform full `O(n)` scans over applied attributes. Also clarify guidance for repeated overlap-style queries: use `AttributeSegmentsWorkspace` to segment once and intersect query ranges with yielded segments to recover exact covered subranges. --- attributed_text/src/attributed_text.rs | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/attributed_text/src/attributed_text.rs b/attributed_text/src/attributed_text.rs index 6ad702a4..f5c51b0f 100644 --- a/attributed_text/src/attributed_text.rs +++ b/attributed_text/src/attributed_text.rs @@ -89,6 +89,8 @@ impl AttributedText { /// /// Attributes are yielded in the order they were applied. This doesn't handle conflicting /// attributes, it just reports everything. + /// + /// This performs a full scan of all attributes on each call (`O(n)` in applied span count). pub fn attributes_at(&self, index: usize) -> impl Iterator, &Attr)> { self.attributes.iter().filter_map(move |(attr_span, attr)| { if attr_span.contains(&index) { @@ -103,6 +105,13 @@ impl AttributedText { /// /// Attributes are yielded in the order they were applied. This doesn't handle conflicting /// attributes, it just reports everything. + /// + /// This performs a full scan of all attributes on each call (`O(n)` in applied span count). + /// + /// Use this for one-off overlap queries. For many queries over the same text, prefer + /// segment-based iteration with [`AttributeSegmentsWorkspace`](crate::AttributeSegmentsWorkspace): + /// segment once, then intersect your query ranges with yielded segments (which also provides + /// the exact covered subranges). pub fn attributes_for_range( &self, range: Range,