From: Duncan C. <dun...@wo...> - 2005-12-07 13:57:22
|
On Wed, 2005-12-07 at 13:06 +0000, Axel Simon wrote: > On Wed, 2005-12-07 at 12:22 +0000, Duncan Coutts wrote: > > On Sun, 2005-11-27 at 10:59 +0000, Axel Simon wrote: > > > Here's a couple functions for getting and setting integers of 'count' > > bits at offset 'off' into the 96 bits of the Iter. > > > > getBitSlice :: Iter -> Int -> Int -> Word32 > > getBitSlice (Iter a b c) off count = > > getBitSliceWord32 a off count > > .|. getBitSliceWord32 b (off-32) count > > .|. getBitSliceWord32 c (off-64) count > > > > where getBitSliceWord32 :: Word32 -> Int -> Int -> Word32 > > getBitSliceWord32 word off count = > > word `shiftR` off .&. (1 `shiftL` count - 1) > > > > setBitSlice :: Iter -> Int -> Int -> Word32 -> Iter > > setBitSlice (Iter a b c) off count value = > > assert (value < 1 `shiftL` count) $ > > Iter (setBitSliceWord32 a off count value) > > (setBitSliceWord32 b (off-32) count value) > > (setBitSliceWord32 c (off-64) count value) > > > > where setBitSliceWord32 :: Word32 -> Int -> Int -> Word32 -> Word32 > > setBitSliceWord32 word off count value = > > let mask = (1 `shiftL` count - 1) `shiftL` off > > in (word .&. complement mask) .|. (value `shiftL` off) > > Ok, so you can do it :-) Yeah, ok that was overkill. :-) I could have just said "actually it's not too hard". > > > To advertise my suggestion... Advancing iterators is O(1) in all cases, > > > even if you iter through the children (which requires a hashtable > > > lookup). And it is a bit simpler to implement. > > > > That sounds good! > > > > > That said, we could have both approaches. > > > > I've mostly implemented (but not fully tested) the above approach. (See > > the attached screenshot.) I might have a go with your suggestion and see > > how they compare. > > Maybe you can commit something, so I can look at it? Sure. I'll start by committing the low level bits (C parts + low level Haskell wrapper) and post the high level bits to the list for review. > No rush, though, I'm supposed to work on my PhD (and spent the whole > morning adding the onInsertText signal). Heh. Yeah that signal bocking/stopping stuff is less than pleasant. Duncan |