Page 2 of 2

Re: Inconsistent String Behavior

Posted: Sat Dec 20, 2014 9:20 am
by Tronic
this is the class I use for Bitmask, it take only 199 byte space to store 1024 bit in the string preset

Code: Select all

class Bitmask
 
	def initialize
		@mask = 0
	end
	
	def set idx
		@mask |= 1 << idx
	end
	
	def unset idx
		@mask &= ~(1 << idx)
	end
	
	def get idx
		@mask & (1 << idx) > 0
	end

	def clear
		@mask = 0
	end
	
	def save
		@mask.to_s(36)
	end
	
	def load data
		@mask = data.to_i(36)
	end
end
Edit: some correction

Re: Inconsistent String Behavior

Posted: Sat Dec 20, 2014 6:15 pm
by tulamide
I don't see where this is any different, apart from my additional safety (I'm avoiding null bytes and don't use bignums, but fixnums, because they are accessed with fewer cycles). Also, I'm already down to 148 bytes (for 1035 states) ;)