fixes parfaits hash by implementing array
basic concept holds up as parfaits hash is now working on parfaits own array
This commit is contained in:
@ -2,6 +2,43 @@
|
||||
|
||||
module Parfait
|
||||
class Array < Object
|
||||
|
||||
# push means add to the end
|
||||
# this automatically grows the array
|
||||
def push value
|
||||
self.set( length , value)
|
||||
end
|
||||
|
||||
def set( index , value)
|
||||
raise "negative index for set #{len}" if index < 0
|
||||
if index >= self.length
|
||||
grow_to(index)
|
||||
end
|
||||
internal_object_set( index , value)
|
||||
end
|
||||
|
||||
def get(index)
|
||||
raise "negative index for get #{len}" if index < 0
|
||||
if index >= self.length
|
||||
return nil
|
||||
else
|
||||
return internal_object_get(index)
|
||||
end
|
||||
end
|
||||
|
||||
def empty?
|
||||
self.length == 0
|
||||
end
|
||||
|
||||
def grow_to(len)
|
||||
raise "negative length for grow #{len}" if len < 0
|
||||
return unless len > self.length
|
||||
index = self.length
|
||||
internal_object_grow(length)
|
||||
while( index < self.length )
|
||||
internal_object_set( index , nil)
|
||||
end
|
||||
end
|
||||
#many basic array functions can not be defined in ruby, such as
|
||||
# get/set/length/add/delete
|
||||
# so they must be defined as CompiledMethods in Builtin::Kernel
|
||||
|
@ -23,7 +23,7 @@ module Parfait
|
||||
def get(key)
|
||||
index = key_index(key)
|
||||
if( index )
|
||||
@values[index]
|
||||
@values.get(index)
|
||||
else
|
||||
nil
|
||||
end
|
||||
@ -37,7 +37,7 @@ module Parfait
|
||||
index = 0
|
||||
found = nil
|
||||
while(index < len)
|
||||
if( @keys[index] == key)
|
||||
if( @keys.get(index) == key)
|
||||
found = index
|
||||
break
|
||||
end
|
||||
@ -49,7 +49,7 @@ module Parfait
|
||||
def set(key , value)
|
||||
index = key_index(key)
|
||||
if( index )
|
||||
@keys[index] = value
|
||||
@keys.set(index , value)
|
||||
else
|
||||
@keys.push(key)
|
||||
@values.push(value)
|
||||
|
@ -12,7 +12,7 @@
|
||||
# may be added to any object at run-time
|
||||
|
||||
module Parfait
|
||||
class Module
|
||||
class Module < Object
|
||||
# :<, :<=, :>, :>=, :included_modules, :include?, :name, :ancestors, :instance_methods, :public_instance_methods,
|
||||
# :protected_instance_methods, :private_instance_methods, :constants, :const_get, :const_set, :const_defined?,
|
||||
# :const_missing, :class_variables, :remove_class_variable, :class_variable_get, :class_variable_set,
|
||||
|
Reference in New Issue
Block a user