hyf

Context-aware query service for Radroots
git clone https://radroots.dev/git/hyf.git
Log | Files | Refs | README | LICENSE

match_index.mojo (1311B)


      1 from std.collections import List
      2 
      3 
      4 def index_supplied_lots(
      5     lot_ids: List[String], revisions: List[String]
      6 ) raises -> List[String]:
      7     if len(lot_ids) != len(revisions):
      8         raise Error("lot ids and revisions must align")
      9     if len(lot_ids) == 0:
     10         raise Error("matching requires at least one supplied lot")
     11     var keys = List[String]()
     12     var seen_ids = List[String]()
     13     var seen_revisions = List[String]()
     14     for index in range(len(lot_ids)):
     15         var lot = String(lot_ids[index])
     16         var rev = String(revisions[index])
     17         if (
     18             String(lot).strip().byte_length() == 0
     19             or String(rev).strip().byte_length() == 0
     20         ):
     21             raise Error("supplied lot requires id and revision")
     22         var key = lot + "@" + rev
     23         for existing in keys:
     24             if existing == key:
     25                 raise Error("duplicate supplied lot revision: " + key)
     26         var id_seen = False
     27         for known in seen_ids:
     28             if known == lot:
     29                 id_seen = True
     30         if id_seen:
     31             raise Error("conflicting revisions for lot: " + lot)
     32         seen_ids.append(String(lot))
     33         seen_revisions.append(String(rev))
     34         keys.append(String(key))
     35     return keys^
     36 
     37 
     38 def duplicate_records_double_stock() -> Bool:
     39     return False