[erlang-questions] 2D Map Arrays

Jeff Crane jefcrane@REDACTED
Mon Sep 11 21:37:34 CEST 2006



--- Richard Carlsson <richardc@REDACTED> wrote:

> Jeff Crane wrote:
> > Can anyone post example usage for the Array
> > implementation? 
> > 
> > I'd like to see proper usage.
> > 
> On the other hand, there _is_ a heap of unit testing
> code
> inside the module, with plenty of usage examples.

I dont see it.

-ifdef(EUNIT).
new_test_() ->
    N0 = ?LEAFSIZE,
    N01 = N0+1,
    N1 = ?NODESIZE*N0,
    N11 = N1+1,
    N2 = ?NODESIZE*N1,
   
[?_assertMatch(#array{size=0,max=N0,default=undefined,elements=N0},
		   new(0)),
     ?_assertMatch(#array{size=N0,max=N0,elements=N0},
new(N0)),
    
?_assertMatch(#array{size=N01,max=N1,elements=N1},
new(N01)),
     ?_assertMatch(#array{size=N1,max=N1,elements=N1},
new(N1)),
    
?_assertMatch(#array{size=N11,max=N2,elements=N2},
new(N11)),
     ?_assertMatch(#array{size=N2, max=N2,
default=42,elements=N2},
		   new(N2,42)),
     ?_assert(new() == new(0)),
     ?_assert(new(0) == new(0,undefined)),
     ?_assert(0 == array:size(new())),
     ?_assert(undefined == default(new())),
     ?_assert(new(10) == new(10,undefined)),
     ?_assert(17 == array:size(new(17))),
     ?_assert(4711 == default(new(0,4711)))     
    ].
-endif.

This doesn't have any real meaning to me. I'm sure
it's because I don't have enough erlang experience to
understand what that's supposed to do, but it's nearly
incomprehensible compared to 

> Did you not see the html documentation
> (http://user.it.uu.se/~richardc/array/array.html)?

Which I had not seen.

> > How do I push a value into the array?
> 
> Use the 'set' function. I will probably add some
> extra functions such as 'append' later.
> 
> > Does it dynamically resize?
> 
> Yes.

test() ->
	MyNewArr = array:new(0,0),
	MyBiggerArr = array:set(1,4,MyNewArr),
	array:size(MyBiggerArr).

That's an example I can understand. Arrays are
identified by the tuples returned from array:new

All functions are essentially read-only functions, but
you cannot reassign variables so this requires
reassignment to new Atoms as the array is processed.

I now know more about how to use the Array module for
temporary data storage than I know about ets (
http://www.google.com/search?hl=en&lr=&safe=off&q=usage+erlang+example+ets&btnG=Search
- that's a lot of digging for not much in the way of
examples).


Yes, I'm not amazingly good at learning how to read
and use erlang modules, but I am happy to be the
newbie filter. 


__________________________________________________
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around 
http://mail.yahoo.com 



More information about the erlang-questions mailing list