Branch: Tag:

2001-12-10

2001-12-10 02:08:17 by Martin Stjernholm <mast@lysator.liu.se>

Multiset implementation using rbtree. --with-new-multisets required to
enable it. There's still no glue to use most of the new features, except
that the iterator (and foreach) works without locking the multiset index,
and that multiset data blocks use copy-on-write (just like mappings).

Rev: src/acconfig.h:1.94
Rev: src/builtin.cmod:1.71
Rev: src/builtin_functions.c:1.416
Rev: src/configure.in:1.562
Rev: src/docode.c:1.137
Rev: src/encode.c:1.133
Rev: src/gc.c:1.178
Rev: src/interpret.c:1.253
Rev: src/iterators.cmod:1.15
Rev: src/main.c:1.138
Rev: src/multiset.c:1.40
Rev: src/multiset.h:1.20
Rev: src/opcodes.c:1.117
Rev: src/operators.c:1.143
Rev: src/pike_types.c:1.183

1:   /* -*- c -*- -  * $Id: builtin.cmod,v 1.70 2001/11/08 23:34:27 nilsson Exp $ +  * $Id: builtin.cmod,v 1.71 2001/12/10 02:08:12 mast Exp $    */      #include "global.h"
595:      PIKEFUN int get_weak_flag(multiset m)   { + #ifdef PIKE_NEW_MULTISETS +  RETURN multiset_get_flags(m) & MULTISET_WEAK; + #else    RETURN (m->ind->flags & (ARRAY_WEAK_FLAG|ARRAY_WEAK_SHRINK)) ?    PIKE_WEAK_INDICES : 0; -  + #endif   }      PIKEFUN program __empty_program()
773:      PIKEFUN mixed random(multiset m)   { -  if(!m->ind->size) +  if(multiset_is_empty (m))    SIMPLE_BAD_ARG_ERROR("random", 1, "multiset with elements in it"); -  + #ifdef PIKE_NEW_MULTISETS +  if (multiset_indval (m)) { +  ptrdiff_t nodepos = multiset_get_nth (m, my_rand() % multiset_sizeof (m)); +  push_multiset_index (m, nodepos); +  push_multiset_value (m, nodepos); +  sub_msnode_ref (m); +  f_aggregate (2); +  } +  else { +  push_multiset_index (m, multiset_get_nth (m, my_rand() % multiset_sizeof (m))); +  sub_msnode_ref (m); +  } + #else    push_svalue(m->ind->item + (my_rand() % m->ind->size)); -  + #endif    stack_swap();    pop_stack();   }    - PIKEFUN mapping random(mapping m) + PIKEFUN array random(mapping m)   {    struct mapping_data *md=m->data;    size_t bucket, count;