Changeset 3621 for proto


Ignore:
Timestamp:
Feb 3, 2014, 6:24:22 AM (6 years ago)
Author:
cameron
Message:

remove1, removeRange

File:
1 edited

Legend:

Unmodified
Added
Removed
  • proto/RE/Haskell/SparseCharSet.hs

    r3620 r3621  
    2828  | otherwise = True
    2929
    30 
    3130-- Insert a codepoint into a class
    3231insert1 :: (CodePoint, SparseCharClass) -> SparseCharClass
     
    3938  | hi < a-1      = CharRange(lo, hi):CharRange(a, b):more
    4039  | lo > b+1      = CharRange(a, b):insertRange(lo, hi, more)
    41 -- Ranges overlap, insert the combined range
     40-- Ranges overlap, insert the combined range.  But do it
     41-- recursively to possibly collapse even further.
    4242  | otherwise     = insertRange(min a lo, max b hi, more)
    4343
     
    5555
    5656
     57-- Remove a codepoint from a class
     58remove1 :: (CodePoint, SparseCharClass) -> SparseCharClass
     59remove1 (c, cc) = removeRange(c, c, cc)
     60
     61-- Insert a range of codepoints into a class
     62removeRange :: (CodePoint, CodePoint, SparseCharClass) -> SparseCharClass
     63removeRange(lo, hi, []) = []
     64removeRange(lo, hi, CharRange(a, b):more)
     65  | hi < a-1            = CharRange(a, b):more
     66  | lo > b+1            = CharRange(a, b):removeRange(lo, hi, more)
     67-- Ranges overlap
     68  | lo <= a && hi >=b   = removeRange(lo, hi, more)
     69  | lo <= a             = CharRange(hi+1, b):more
     70  | hi >= b             = CharRange(a, lo-1):removeRange(lo, hi, more)
     71  | otherwise           = CharRange(a, lo-1):CharRange(hi+1,b):more
     72
Note: See TracChangeset for help on using the changeset viewer.