void DjVuPortcaster::compute_closure(const DjVuPort * src, GPList<DjVuPort> &list, bool sorted) { GCriticalSectionLock lock(&map_lock); GMap<const void*, void*> set; if (route_map.contains(src)) { GList<void *> & list=*(GList<void *> *) route_map[src]; for(GPosition pos=list;pos;++pos) { DjVuPort * dst=(DjVuPort *) list[pos]; if (dst==src) add_to_closure(set, src, 0); else add_to_closure(set, dst, 1); } } // Compute list GPosition pos; if (sorted) { // Sort in depth order int max_dist=0; for(pos=set;pos;++pos) if (max_dist < (int)(long)set[pos]) max_dist = (int)(long)set[pos]; GArray<GList<const void*> > lists(0,max_dist); for(pos=set;pos;++pos) lists[(int)(long)set[pos]].append(set.key(pos)); for(int dist=0;dist<=max_dist;dist++) for(pos=lists[dist];pos;++pos) { GP<DjVuPort> p = is_port_alive((DjVuPort*) lists[dist][pos]); if (p) list.append(p); } } else { // Gather ports without order for(pos=set;pos;++pos) { GP<DjVuPort> p = is_port_alive((DjVuPort*) set.key(pos)); if (p) list.append(p); } } }
void DjVuPalette::allocate_hist() { if (! hist) { hist = new GMap<int,int>; mask = 0; } else { GMap<int,int> *old = hist; hist = new GMap<int,int>; mask = (mask<<1)|(0x010101); for (GPosition p = *old; p; ++p) { int k = old->key(p); int w = (*old)[p]; (*hist)[k | mask] += w; } delete old; } }
static GUTF8String getbodies( GList<GURL> &paths, const GUTF8String &MessageFileName, GPList<lt_XMLTags> &body, GMap<GUTF8String, void *> & map ) { GUTF8String errors; bool isdone=false; GPosition firstpathpos=paths; for(GPosition pathpos=firstpathpos;!isdone && pathpos;++pathpos) { const GURL::UTF8 url(MessageFileName,paths[pathpos]); if(url.is_file()) { map[MessageFileName]=0; GP<lt_XMLTags> gtags; { GP<ByteStream> bs=ByteStream::create(url,"rb"); G_TRY { gtags=lt_XMLTags::create(bs); } G_CATCH(ex) { GUTF8String mesg(failed_to_parse_XML+("\t"+url.get_string())); if(errors.length()) { errors+="\n"+mesg; }else { errors=mesg; } errors+="\n"+GUTF8String(ex.get_cause()); } G_ENDCATCH; } if(gtags) { lt_XMLTags &tags=*gtags; GPList<lt_XMLTags> Bodies=tags.get_Tags(bodystring); if(! Bodies.isempty()) { isdone=true; for(GPosition pos=Bodies;pos;++pos) { body.append(Bodies[pos]); } } GPList<lt_XMLTags> Head=tags.get_Tags(headstring); if(! Head.isempty()) { isdone=true; GMap<GUTF8String, GP<lt_XMLTags> > includes; lt_XMLTags::get_Maps(includestring,namestring,Head,includes); for(GPosition pos=includes;pos;++pos) { const GUTF8String file=includes.key(pos); if(! map.contains(file)) { GList<GURL> xpaths; xpaths.append(url.base()); const GUTF8String err2(getbodies(xpaths,file,body,map)); if(err2.length()) { if(errors.length()) { errors+="\n"+err2; }else { errors=err2; } } } } } } } }