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

27:   #include "bignum.h"   #include "operators.h"    - RCSID("$Id: opcodes.c,v 1.116 2001/09/24 14:58:05 grubba Exp $"); + RCSID("$Id: opcodes.c,v 1.117 2001/12/10 02:08:15 mast Exp $");      void index_no_free(struct svalue *to,struct svalue *what,struct svalue *ind)   {
660:    if(run_time_itype != T_MIXED)    {    struct multiset *m; + #ifdef PIKE_NEW_MULTISETS +  struct multiset *tmp=sp[-2].u.multiset; + #else    struct array *tmp=sp[-2].u.multiset->ind; -  + #endif    DECLARE_CYCLIC();       if((m=(struct multiset *)BEGIN_CYCLIC(tmp,0)))    {    ref_push_multiset(m);    }else{ -  INT32 e; -  struct array *a; +    #ifdef PIKE_DEBUG    struct svalue *save_sp=sp+1;   #endif -  +  + #ifdef PIKE_NEW_MULTISETS +  ptrdiff_t nodepos; +  if (multiset_indval (tmp)) +  Pike_error ("FIXME: Casting not implemented for multisets with values.\n"); +  push_multiset (m = allocate_multiset (multiset_sizeof (tmp), +  multiset_get_flags (tmp), +  multiset_get_cmp_less (tmp))); +  +  SET_CYCLIC_RET(m); +  +  if ((nodepos = multiset_first (tmp)) >= 0) { +  ONERROR uwp; +  SET_ONERROR (uwp, do_sub_msnode_ref, tmp); +  do { +  push_multiset_index (tmp, nodepos); +  o_cast(itype, run_time_itype); +  multiset_insert_2 (m, sp - 1, NULL, 0); +  pop_stack(); +  } while ((nodepos = multiset_next (tmp, nodepos)) >= 0); +  UNSET_ONERROR (uwp); +  } +  + #else /* PIKE_NEW_MULTISETS */ +  INT32 e; +  struct array *a;    push_multiset(m=allocate_multiset(a=allocate_array(tmp->size)));       SET_CYCLIC_RET(m);
683:    array_set_index(a,e,sp-1);    pop_stack();    } +  order_multiset(m); + #endif +    #ifdef PIKE_DEBUG    if(save_sp!=sp)    fatal("o_cast left stack droppings.\n");   #endif -  order_multiset(m); +     }    END_CYCLIC();    assign_svalue(sp-3,sp-1);