Package com.trifork.clj_ds

Examples of com.trifork.clj_ds.IPersistentCollection


  public ESeq matching_values_bag(ESeq vals,
      Map<EObject, IPersistentCollection> map) {
   
    for (Map.Entry<EObject, IPersistentCollection> ent : map.entrySet()) {

      IPersistentCollection values = ent.getValue();
      for (ISeq seq = values.seq(); seq != null; seq = seq.next()) {
        ETuple val = (ETuple) seq.first();
        if (matches(val)) {
          vals = vals.cons(val);
        }
      }
View Full Code Here


    private final ISeq coll;
    private final ISeq map_seq;

    ELSeq(ISeq map) {
      IMapEntry collent = (IMapEntry)map.first();
      IPersistentCollection c = (IPersistentCollection) collent.getValue();
     
      while (c.count() == 0) {
        map = map.next();
        collent = (IMapEntry) map.first();
        c = (IPersistentCollection) collent.getValue();
      }
     
      coll = c.seq();
      map_seq = map.next();
    }
View Full Code Here

        int count = 0;
        for (ESeq seq = values; !seq.isNil(); seq = seq.tail()) {
          ETuple value = seq.head().testTuple();
          if (value == null) throw ERT.badarg(values);
          EObject key = get_key(value);
          IPersistentCollection c =
            (IPersistentCollection) map.valAt(key, empty());

          // Insert element - noting whether the map grows
          int sizeBefore = c.count();
          c = c.cons(value);
          int sizeAfter = c.count();
          map = map.assoc(key, c);

          // Update size - if the map grew
          if (sizeAfter > sizeBefore) count += 1;
        }
View Full Code Here

  @Override
  protected void insert_one(final ETuple value) {
    in_tx(new WithMap<Object>() {
      @Override
      protected Object run(IPersistentMap map) {
        IPersistentCollection empty = empty();
        EObject key = get_key(value);
        IPersistentCollection c =
          (IPersistentCollection) map.valAt(key, empty);

        // Insert element - noting whether the map grows
        int sizeBefore = c.count();
        c = c.cons(value);
        int sizeAfter = c.count();
        map = map.assoc(key, c);
        set(map);

        // Update size - if the map grew
        Integer cnt0 = (Integer)sizeRef.get();
View Full Code Here

  /** return a list of elements at given key */
  @Override
  protected ESeq lookup(EObject key) {
    IPersistentMap ipm = deref();
    IPersistentCollection set = (IPersistentCollection) ipm.valAt(key);
    ESeq res = ERT.NIL;
    if (set == null) return res;
    for(ISeq s = set.seq(); s != null; s = s.next())
    {
      res = res.cons((EObject) s.first());
    }   
    return res.reverse();
  }
View Full Code Here

  }

  @Override
  protected EAtom member(EObject key) {
    IPersistentMap ipm = deref();
    IPersistentCollection set = (IPersistentCollection) ipm.valAt(key);
    if (set != null && set.count() != 0) {
      return ERT.TRUE;
    } else {
      return ERT.FALSE;
    }
  }
View Full Code Here

     
      return res.reverse();
    }
   
    IPersistentMap map = deref();
    IPersistentCollection coll = (IPersistentCollection) map.valAt(key);
    if (coll == null) return ERT.NIL;
   
    return matcher.match_vars(ERT.NIL, coll.seq()).reverse();
  }
View Full Code Here

     
      return res.reverse();
    }
   
    IPersistentMap map = deref();
    IPersistentCollection coll = (IPersistentCollection) map.valAt(key);
    if (coll == null) return ERT.NIL;
   
    return matcher.match_members(ERT.NIL, coll.seq()).reverse();
  }
View Full Code Here

  @Override
  protected void delete(final EObject key) {
    in_tx(new WithMap<Object>() {
      @Override
      protected Object run(IPersistentMap map) {
        IPersistentCollection empty = empty();
        IPersistentCollection c =
          (IPersistentCollection) map.valAt(key, empty);
        try {
            map = map.without(key);
        } catch (Exception e) {
            // should not happen!
            throw new Error(e);
        }
        set(map);
        sizeRef.addAndGet(- c.count());
        return null;
      }
    });
  }
View Full Code Here

  protected void delete_object(final ETuple obj) {
    in_tx(new WithMap<Object>() {
      @Override
      protected Object run(IPersistentMap map) {
        EObject key = get_key(obj);
        IPersistentCollection empty = empty();
        IPersistentCollection c =
          (IPersistentCollection) map.valAt(key, empty);
       
        if (c == null || c.count()==0)
          return null;
       
        IPersistentCollection out = empty();
        int deleted = 0;
       
        for (ISeq s = c.seq(); s != null; s = s.next()) {
          EObject val = (EObject) s.first();
          if (val == null) break;
         
          if (! obj.equalsExactly(val)) {
            out = out.cons(val);
          } else {
            deleted += 1;
          }
        }
       
        if (out.count() == 0) {
          try {
            map = map.without(key);
          } catch (Exception e) {
            throw new Error(e);
          }
View Full Code Here

TOP

Related Classes of com.trifork.clj_ds.IPersistentCollection

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.