asp.net open pdf in new window code behind : Change font size pdf application SDK tool html winforms wpf online ITU-TR-2006-7621-part694

§11.6
Topologicalsort 209
11.6 Topologicalsort
Thisexampleconcerns topologicalsorting;it isin le
Toposort.cs
. Atopological
sortofadirectedacyclicgraphisalinearorderingofthegraph’snodes,suchthatif
nodeapointstonodebinthegraph,noteda!b,thena<binthelinearordering.
Notethattheremaybemanydifferentsuchlinearorderingsforagivengraph.For
instance,considerthegraphingure11.4.
b
c
e
a
d
Figure11.4:Adirectedacyclicgraphwithnodesa,b,c,dande.
Thegraphhaslinearorderingsa<b<c<d<ebutalsoa<b<c<e<dand
a<c<b<d<eanda<c<b<e<danda<c<e<b<d.
Topologicalsortmaybeusedinaspreadsheetimplementation.Eachcellformula
inthespreadsheetisanode,anditschildrenarethecellsthattheformularefersto,
thatis,thecellsonwhichitsvaluedepends. Atopologicalsortofthecellformulas
canbeusedtodeterminetheorderinwhichtoevaluatethecellformulasaftera
change.
11.6.1 Representationofgraphnodes
Assumethatagraphnodehasaname
id
andzeroormorechildnodes. Agraph
consistsofasetofsuchnodes,togetherwithasetofsomeofthenodescalledthe
startset. Moreconcretely,letanodewithidoftypeTberepresentedinC#byan
objectoftypeNode<T>:
public class Node<T> > {
public readonly y T T id;
public readonly y Node<T>[] children;
// All l non-null
public Node(T T id, , params s Node<T>[] children) {
this.id = id; this.children n = = children;
}
public Node(Node<T> node) ) : : this(node.id, new w Node<T>[node.children.Length])
{ }
}
Thus
new Node(id,
n
1
, ...,
n
k
)
createsanodewithname
id
andchildrenn
1
;:::;n
k
.
Forinstance,ifnodenamesarerepresentedasstrings,thegraphingure11.4can
becreatedusingthisC#declaration:
Change font size pdf - Compress reduce PDF size in C#.net, ASP.NET, MVC, Ajax, WinForms, WPF
C# Code & .NET API to Compress & Decompress PDF Document
change font size in fillable pdf; change font size in pdf file
Change font size pdf - VB.NET PDF File Compress Library: Compress reduce PDF size in vb.net, ASP.NET, MVC, Ajax, WinForms, WPF
VB.NET PDF Document Compression and Decompression Control SDK
best way to compress pdf file; change file size of pdf document
210 Topologicalsort
§11.6
Node<String>
d = new Node<String>("d"),
e = new Node<String>("e"),
c = new Node<String>("c", d, e),
b = new Node<String>("b", d),
a = new Node<String>("a", b, c, d);
11.6.2 Standarddepth-rsttopologicalsort
Thestandardalgorithmfortopologicalsortplacesthegraphnodesintheorderof
increasingnishtimeinadepth-rstsearchofthegraphfromthenodesinthestart
set[9,section22.4].
ThisiseasilyimplementedusingtheHashedLinkedList<T>classoftheC5 li-
brary. Weneedtwo o methods,
Toposort0
and
AddNode0
, where method
Toposort0
takesasargumentthestartset,createsanewemptylistofsortednodes,andthen
foreachstartnodeaddsallitsdescendants:
public static IList<Node<T>> > Toposort0<T>(params s Node<T>[] starts) {
HashedLinkedList<Node<T>> sorted = new w HashedLinkedList<Node<T>>();
foreach (Node<T> start t in starts)
if (!sorted.Contains(start))
AddNode0(sorted, start);
return sorted;
}
Method
AddNode0
takesasargumentanodewhichisnotyetinthesortedlist. For
eachchildofthegivennodeitaddsallthechild’sdescendantsbycallingitselfre-
cursively,andnallyaddsthenode:
private static c void d AddNode0<T>(IList<Node<T>> > sorted, Node<T> node) {
SDD.Assert(!sorted.Contains(node));
foreach (Node<T> child d in node.children)
if (!sorted.Contains(child))
AddNode0(sorted, child);
sorted.InsertLast(node);
}
Providedthegraphcontainsnocycles,method
Toposort0
returnsa sortedlistof
nodeswiththefollowingproperty: everynodeappearsstrictlyafterallitsdescen-
dants. Ifthealgorithmterminates,ittakestimelinearinthenumberofnodesin
thegraph. However,ifthegraphcontains s a cycle,then therewill bean innite
sequenceofcallsto
AddNode0
andtheprogramwillfailwithstackoverow.
Thecall
SDD.Assert(...)
istomethod
Assert
inclassSystem.Diagnostics.Debug.
Itisusedtoassertapreconditionformethod
AddNode0
,andhasnoeffectatruntime
unlesstheexampleiscompiledwithoption
/d:DEBUG
.
C# PDF insert text Library: insert text into PDF content in C#.net
Powerful .NET PDF edit control allows modify existing scanned PDF text. Ability to change text font, color, size and location and output a new PDF document.
change font size pdf fillable form; change font size in fillable pdf form
C# PDF Annotate Library: Draw, edit PDF annotation, markups in C#.
Able to edit and change PDF annotation properties such as font size or color. Abilities to draw markups on PDF document or stamp on PDF file.
change paper size in pdf document; pdf font size change
§11.6
Topologicalsort 211
11.6.3 Improveddepth-rstalgorithmfortopologicalsort
Theimplementationoftopologicalsortshownaboveexploitsthatinahashedlinked
list,itisveryfasttodetermine(using
Contains
)whetheranodeisinthelist. By
exploitingalsothatahashedlinkedlistknowswhereanodeisinthelist,weget
a slightlybetternon-standardalgorithmfortopologicalsort: : onethatterminates
evenifthegraphcontainscycles. Themaindifferenceisthattheabovestandard
algorithmaddsanodeafteraddingitsdescendants,whereasthenon-standardal-
gorithmbelowaddsanodebeforeaddingsitsdescendants.
Method
Toposort1
thattakesasargumentthesetofstartnodes,createsanew
emptylistofsortedgraphnodes,andthenaddseachstartnodeanditsdescendants:
public static IList<Node<T>> Toposort1<T>(params Node<T>[] starts) {
HashedLinkedList<Node<T>> sorted = new w HashedLinkedList<Node<T>>();
foreach (Node<T> > start in starts)
if (!sorted.Contains(start)) ) {
sorted.InsertLast(start);
AddNode1(sorted, start);
}
return sorted;
}
Method
AddNode1
takesasargumentanodewhichisalreadyinthesortedlist.For
eachchildofthegivennodeitaddsthatchildjustbeforethegivennode,andthen
addsallthechild’sdescendantsbycallingitselfrecursively.
private static void d AddNode1<T>(IList<Node<T>> sorted, , Node<T> > node) ) {
SDD.Assert(sorted.Contains(node));
foreach (Node<T> > child in node.children)
if (!sorted.Contains(child)) ) {
sorted.ViewOf(node).InsertFirst(child);
AddNode1(sorted, child);
}
}
Providedthegraphcontains nocycles,method
Toposort1
returns a sortedlist of
nodesinwhicheverynodeappearsstrictlyafterallitsdescendants.Also,ittermi-
natesevenincasethegraphcontainscycles,butinthatcase,therewillbeatleast
onenodeinthesortedlistthatdoesnotappearstrictlyafterall itsdescendants.
Thealgorithmtakestimelinearinthenumberofnodesinthegraph.
Notethatthepreconditionof
AddNode1
isthelogicalnegationofthatof
AddNode0
.
Themainshortcomingoftheabovedepth-rstalgorithmsisthattheymayper-
formlongchainsofrecursivemethodcalls,andthusmayoverowthemethodcall
stack. Namely,ifthegraphcontainsa a chainoftheforma
1
!a
2
!a
3
!!a
n
wherea
1
haschilda
2
,anda
2
andchilda
3
soon,thentheremaybeachainofcalls
ofthe
AddNode
methodsthathasdepthn.
Thisshortcomingcanbeaddressedbykeepinganexplicitstack(usinganarray
list,forinstance)ofnodechildrenyettovisit. Alternatively,onemayconsiderthe
C# PDF Sticky Note Library: add, delete, update PDF note in C#.net
Allow users to add comments online in ASPX webpage. Able to change font size in PDF comment box. Able to save and print sticky notes in PDF file.
change font size fillable pdf; adjust pdf page size
C# PDF Convert to Word SDK: Convert PDF to Word library in C#.net
PDF document, keeps the elements (like images, tables and chats) of original PDF file and maintains the original text style (including font, size, color, links
pdf change page size; pdf reduce file size
212 Topologicalsort
§11.6
sortedlistitselfasaworklistofnodeswhosechildrenshouldbeconsidered,using
alistviewasacursor.Thisisattheexpenseofsomeextrawork,especiallyifsome
nodesmayhavemanychildren.
11.6.4 Topologicalsortbyrescanningthesortedlist
Thelastversionoftopologicalsortconsideredhereusesaone-itemlistviewasa
cursortoscanthesortedlist. Whenanewnodeisinsertedintothelist,thecursor
pointsatthatnode.Ifthenodeunderthecursorhasapendingchildachildnot
yetonthesortedlist that childisinsertedinattheleftendofthecursor,the
cursorismovedleftby
Slide(0,1)
,andthesameprocessisrepeated. Otherwise,
thecursorismovedrightby
TrySlide(+1)
untilanodeisfoundthathasapending
child,oruntiltherightendofthelistisreached.Theloopinvariantisthatnonode
strictlytotheleftofthecursorhasapendingchild.
public static IList<Node<T>> > Toposort2<T>(params s Node<T>[] starts) {
HashedLinkedList<Node<T>> sorted = new w HashedLinkedList<Node<T>>();
foreach (Node<T> start t in starts)
if (!sorted.Contains(start)) ) {
sorted.InsertLast(start);
using (IList<Node<T>> cursor = sorted.View(sorted.Count-1,1)) {
do {
Node<T> child;
while (null != (child = PendingChild(sorted, cursor.First))) ) {
cursor.InsertFirst(child);
cursor.Slide(0,1);
}
} while (cursor.TrySlide(+1));
}
}
return sorted;
}
static Node<T> PendingChild<T>(IList<Node<T>> > sorted, , Node<T> > node) ) {
foreach (Node<T> child d in node.children)
if (!sorted.Contains(child))
return child;
return null;
}
Themaindrawbackofthisprocedureisthatthechildlistofanodemaybescanned
repeatedly,whichmeans thattherunning timefor eachnode e isquadratic in its
numberofchildren. Ifthemaximalnumberofchildrenforanodeisbounded(say,
3),thenthisisnotacauseforconcern.
Generate Barcodes in Web Image Viewer| Online Tutorials
Select "Generate" to process barcode generation; Change Barcode Properties. Select "Font" to choose human-readable text font style, color, size and effects;
change font size pdf; pdf change font size
C# PDF Field Edit Library: insert, delete, update pdf form field
Able to add text field to specified PDF file position in C#.NET class. Support to change font size in PDF form. Able to delete form fields from adobe PDF file.
pdf page size limit; 300 dpi pdf file size
§11.7
Copyingagraph 213
11.7 Copyingagraph
Assumewehaveanarbitrarygraphrepresentedasinsection11.6.1,andthatwe
wanttomakeanexactshallowcopyofthatgraph. Thenewcopymustconsistof
freshNode<T>objects,anditsstructure,asexpressedbythe
children
references,
mustbethesameasthatofthegivenoldgraph,preservingsharingandcycles.This
exampleisinle
Graphcopy.cs
.
11.7.1 Graphcopyingusingarecursivehelpermethod
Onewaytocreatesuchacopyistobuildadictionarythatmapseacholdnodetoa
newnode,usingareferenceequalitycomparertodistinguishnodesbytheirobject
identity.Infact,theresultingdictionaryisanisomorphismbetweentheoldandthe
newgraph.Initiallythedictionaryisempty,andnewgraph’sstartisthecopyofthe
oldgraph’sstartnode.
public static Node<T> > CopyGraph0<T>(Node<T> start) ) {
IDictionary<Node<T>,Node<T>> iso
= new w HashDictionary<Node<T>,Node<T>>
(ReferenceEqualityComparer<Node<T>>.Default);
return CopyNode0(iso, , start);
}
Therealworkisdoneinmethod
CopyNode0
,whichreturnsthenewnodecorrespond-
ingtoagivenoldnode. Iftheoldnodeisalreadyinthedictionary’skeyset,then
thecorrespondingnewnodeisobtainedfromthedictionary.Otherwiseanewnode
iscreatedasacopyoftheoldnode,thedictionaryisextendedtomaptheoldnode
tothenewone,andthenewnode’schildrenaresettobethecopiesoftheoldnode’s
children:
private static Node<T> > CopyNode0<T>(IDictionary<Node<T>,Node<T>> iso,
Node<T> old) {
Node<T> copy;
if (!iso.Find(old, , out t copy)) ) {
copy = = new Node<T>(old);
iso[old] = copy;
for (int i=0; i<copy.children.Length; ; i++)
copy.children[i] = = CopyNode0(iso, old.children[i]);
}
return copy;
}
It is important that dictionary isupdated d before the children ofthe old node is
considered;otherwisethecopyingcouldfailoncyclic graphswhileattemptingto
unrollacycle.
VB.NET Image: Visual Basic .NET Guide to Draw Text on Image in .
Please note that you can change some of the example, you can adjust the text font, font size, font type (regular LoadImage) Dim DrawFont As New Font("Arial", 16
adjust size of pdf in preview; best way to compress pdf files
C# Image: Use C# Class to Insert Callout Annotation on Images
Easy to set annotation filled font property individually Support adjusting callout annotation size parameter in an easy way; C# demo code to change the filled
change paper size in pdf; adjust pdf size
214 Copyingagraph
§11.7
11.7.2 Graphcopyingusinganexplicitstack
Thestraightforwardrecursivealgorithmabovemayfailwitha stackoverowex-
ceptionifappliedtoagraphthathasaverylongpath.Toavoidthat,onemayusea
stackorqueueofpendingnodes:nodeswhosechildrenstillneedtobecopied,asin
thefollowingalgorithm:
public static Node<T> CopyGraph1<T>(Node<T> > start) {
IDictionary<Node<T>,Node<T>> iso
= new HashDictionary<Node<T>,Node<T>>
(ReferenceEqualityComparer<Node<T>>.Default);
IStack<Node<T>> work k = new w ArrayList<Node<T>>();
iso[start] = new w Node<T>(start);
work.Push(start);
while (!work.IsEmpty) ) {
Node<T> node = = work.Pop(), copy y = iso[node];
for (int t i=0; ; i<node.children.Length; i++) ) {
Node<T> child d = = node.children[i];
Node<T> childCopy;
if (!iso.Find(child, , out childCopy)) {
iso[child] = = childCopy y = = new Node<T>(child);
work.Push(child);
}
copy.children[i] = childCopy;
}
}
return iso[start];
}
Asbefore,thedictionarymapsanoldnodetoitsnewcopy. Theworkstackholds
nodesthathavealreadybeencopied,butwhosechildrenmaystillneedtobecopied.
Everynodeinthestackisalsointhekeysetofthedictionary.
§11.8
Generalgraphalgorithms 215
11.8 Generalgraphalgorithms
Thissectiongivesarudimentarydescriptionofamoregeneralgraphlibrary,imple-
mentedinle
Graph.cs
.Thegraphlibraryconsistsofaninterfaceforedge-weighted
graphs, animplementationbasedonanadjacencylistrepresentationusinghash
dictionaries,andtheseexamplealgorithms:
 Breadth-First-SearchandDepth-First-Search,withaninterfacebasedonac-
tionstobetakenasedgesaretraversed. Applicationsare: : checkingforcon-
nectedness,andcountingcomponents.Thisillustratestheuseofhashsetsand
ofLinkedList<Edge<V,E>>todeterminebreadt-rstordepth-rstsearch.
 Priority-First-Search,whereedgesaretraversedaccordingtoeitherweightor
accumulatedweightfromthestartofthesearch. Anapplicationofthenon-
accumulatingversionistheconstructionofaminimalspanningtree,usedin
theapproximatealgorithmfor theTraveling SalesmanProblembelow. . Ap-
plicationsoftheaccumulatingversionare:theconstructionofashortestpath
andthecomputationofthedistancefromonevertextoanotherone.Thisillus-
tratestheuseofhashdictionaries,priorityqueuesandpriorityqueuehandles.
 AnapproximationalgorithmfortheTravelingSalesmanProblem,whenthe
edgeweightssatisesthetriangleinequality[32].
Theinterfacesandclassesofthegraphlibraryusesthesegenericparameters:
 GenericparameterVstandsforthetypeofavertexinagraph. Verticesare
identiedbythe
Equals
method inherited from object t (oroverriddeninthe
vertexclass).
 Generic c parameterEstandsforthetypeofadditional data associatedwith
edgesinagraph.
 GenericparameterWstandsforthetypeofweightson n edgesinaweighted
graph,inpracticeusually
int
or
double
.ValuesoftypeWmustbecomparable,
thatis,
W : IComparable<W>
,andtheremustbegivenacompatiblewaytoadd
valuesoftypeW.
InterfaceIGraph<V,E,W>istheinterfaceforagraphimplementationwithvertex
typeV,edgedatatypeEandedgeweightvaluesoftypeW.
Interface IWeight<E,W> describes s a weight function that maps an edge e data
valueoftypeEtoa weight valueoftypeW,andanoperation toaddtwoweight
valuesoftypeWgivingavalueoftypeW.
ClassHashGraph<V,E,W>providesanimplementationofIGraph<V,E,W>based
onadjacencylistsrepresentedashashdictionaries.
ClassCountWeight<E>implementsIWeight<E,
int
>,classIntWeightimplements
IWeight<
int
,
int
>, andclass DoubleWeight t implements s IWeight<
double
,
double
>,
andtheyareusedtorepresentcommonlyoccurringtypesofedgeweights.
216 Pointlocationintheplane
§11.9
StructtypeEdge<V,E>isthetypeofanedgeinagraphwithverticesoftypeV
andedgedataoftypeE.
DelegatetypeEdgeAction<V,E,U>is thetypeofan actiontoperformoneach
edgewhentraversinga graphwithedgesoftypeEdge<V,E>andwithadditional
edgeinformation(e.g.weightdata)oftypeU.
11.9 Pointlocationintheplane
Assumethat theplaneis dividedintocells,delimitedbyedges(straightlineseg-
ments)suchasthesolidlines ingure11.5. . Forinstance,such h a division may
representplotsofland,theeldsofafarm,ortheroomsandcorridorsofacomplex
building.
(x,y)
x
y
Figure11.5:Dividingtheplaneintoslicesforefcientpointlocation.
Then onecan askthequestion ofany given point (x;y)in theplane: : whichcell
doesthispointbelongto? Thisquestioncanbeansweredefcientlybyusingtree-
basedcollectionsandtaking snapshots (sections6.8 and8.5). . This s isa classical
exampleofusingpersistenttreesbySarnakandTarjan[25].Theexampleisinle
PointLocation.cs
.
Thesolutionistouseanoutersorteddictionarythatmapseachxcoordinateof
anedgeendpointtoaninnersortedsetoftheedgesthatcrossortouchthevertical
lineatthatxcoordinate. Theedgescontainedintheinnersortedsetareordered
bytheirycoordinatestotheimmediaterightofx.Inthegure,thepositionsofthe
innersortedsets areshownasvertical dashedlines. . Notethatthereisaninner
sortedsetforeachedgeendpointintheplane.
§11.9
Pointlocationintheplane 217
Tolookupapoint(x;y)onerstndsthepredecessorofxintheoutersorted
dictionary,searchingonxonly.Theresultisaninnersortedset,inwhichonethen
locatestheedgesaboveandbelow(x;y)bysearchingontheycoordinateonly. The
completelookuptakestimeO(logn)wherenisthenumberofedges.
Thewholedatastructurecanbebuiltefcientlybylettingtheinnersortedsets
besnapshots ofthesamesortedset, createdin orderofincreasing xcoordinate.
Thesesnapshotsarecreatedbymaintainingasortedtreesetofedges,insertingand
deletingedgesduringahorizontal(xaxis)sweep,takingasnapshotoftheinnertree
setandsavingitintheoutersorteddictionaryateachxcoordinatethatcausesone
ormoreedgestobeaddedordeleted.Thussnapshotsaretakenexactlyattheedge
endpoints.
Iftherearenedges, therewill be2nupdates totheinnersortedtree,andin
theworstcase,theinnertreewillhavesizeW(n)forW(n)snapshots. Wewilluse
O(nlogn)timeandO(n)spaceforsortingtheendpoints. SinceC5 5 usesnodecopy
persistence(section13.10)forsnapshotsoftheinnersortedtrees,wewilluseO(n)
spaceandO(n)timetobuildthedatastructure. Thisisfarbetterthanthenaive
approachofmakingfullcopiesofnon-persistentinnertrees,whichwoulduseupto
O(n
2
)spaceandtimetobuildthedatastructure.
LookupwilltakeO(logn)timeinanycase,buttakingthememoryhierarchyinto
consideration,alowspaceuseisverybenecialforlargeproblems.
Thecodeforthisexamplepresentdemonstratestheuseofsnapshotsaswellas
the
Cut
methodfrominterfaceISorted<T>(section4.13).
218 Abatchjobqueue
§11.10
11.10 Abatchjobqueue
Thisexampleconcernsmanagementofcomputerbatchjobsusingpriorityqueues.
Theexampleisinle
Jobqueue.cs
.
TheBlastserverattheNationalCenterforBiotechnologyInformationinMary-
land,USA,can searcha genedatabase forDNAsequences thataresimilar toa
givenDNAsequence.Suchsearchesareperformedfromabatchjobqueue.Topre-
ventasingleuserfromstealingallcpupower,asearchjobsubmittedattimetis
scheduledtobeexecutedattimet+60nwherenisthenumberofsearchjobsfrom
thatusesalreadyinthejobqueue.Henceasinglesearchjobwillbeallowedtorun
immediately(ifthereisaprocessoravailable),butifasecondsearchjobissubmit-
tedimmediatelyaftertherstone,itwillhavetowaitatleast60secondsbeforeit
getsexecuted(ifthereisotherworktodowithanearlierscheduledexecutiontime).
Submittedjobs areidentieduniquebya requestid(RID),andhereweassume
usersareidentiedbythesubmittingmachine’sIPaddress.Submittedjobscanbe
retracted(deleted)usingtheirRID.
LetIpbethetypeofIPnumbers,letRidbethetypeofrequestids,andletJob
bethetypeofsearchjobs.AJobobjectshouldcontainatleastanIp,aRid,andthe
job’sscheduledexecutiontimeandshouldimplementIComparable<Job>basedon
scheduledtime.Wecanimplementthepolicydescribedabovebymaintainingthree
datastructures:
 An n IPriorityQueue<Job> called
jobQueue
that contains thejobs,orderedac-
cordingtoscheduledexecutiontime.
 AnIDictionary<Rid,IPriorityQueueHandle<Job>>called
jobs
thatmapsare-
questidtotheassociatedhandleinthepriorityqueue.
 AHashBag<Ip>called
userJobs
containingtheIPnumbersofusers,withthe
samemultiplicitythatthatuser’sjobsappearinthepriorityqueue. Thereis
noefcientwaytondthisnumberusingonlythepriorityqueue.
Thefollowingoperationscanbeperformedonthebatchjobsystem:
Submit(ip, t)
shouldndthenumberofexistingjobsfromthesameuser
ip
by
userJobs.ContainsCount(ip)
,computethescheduledexecutiontime,create
aRidobject
rid
,createaJobobject
job
andinsertitintothepriorityqueue
obtainingahandle
h
inreturnby
jobQueue.Add(job, out h)
;addthe
ip
tothe
hash bag by
userJobs.Add(ip)
; andinserttherid-to-handlemappinginthe
dictionaryby
jobs[rid] = = h
. Totaltime: O(log(n))wherenisthenumberof
pendingjobs.
ExecuteOne()
shouldnda job with minimalscheduledexecution timeand
removeitfromthepriorityqueueby
job = jobQueue.DeleteMin()
,removethe
job’sIPoncefromthehashbagby
userJobs.Remove(job.ip)
,andremovethe
job’sRIDfromthedictionaryby
jobs.Remove(job.rid)
. Totaltime: O(log(n))
wherenisthenumberofpendingjobs.
Documents you may be interested
Documents you may be interested