Title: ADT
1ADT
????? ???????
??-?? ???? litalma_at_cs.technion.ac.il
2???? ???? ?' ????? ???? 2006
???? ?????? ??????? - ADT (40 ??????) ????? ????
????? ????? ???? ?? ????? ????? ????? ?????
?????? ?? ????? ?? ????? ????? ??????? ?? ??????
?? ????? ?????? ???? ????? ?? ??? ???????. ???
???? ?? ?? ????? ?"? (??????). ??? ????? ??????
????? ?? ??? ???????? ????? ?????? ?????
????? (???? ???? ???? ?? ?????? ??? ????)
???????? ????? ??????. ????? ?????? ?????? ????
?-ADT ??? Image ?????? ????? ????????? ????? ???
???? ??????? ????? imageCopy ???????? ?????
????? ??????? ???? ??? imageDestroy ?????? ??
?? ????? ?????? imagesSimilarity ????? ???
?????? ??????? ???? ???? ??? 0 ?- 1 ????? ??
???? ?????? ??? ???????. ???? ??????? ?? Image
??? "????? ?????", ??? ???? ???? ?? ???? ???????
?? ?????? ??? .
3???? ???? ?' ????? ???? 2006
???? ?' (20 ??????) ???? ?? ???? ????? ?? ??????
SurveillanceSystem ?? ?????? SurSys ?? ?????
????? ????????? ????? ???? CreateSurSys 1
????? SurSys AddWorker 2 ????? ???? ??? ??????
(???????? ????? ?? ??? ??"? ???) AddWorkerImage
3 ????? ????? ?? ???? ????? ?????? (?????? ????
?????? ?????? ??. ???? ?? ??? ?????? ????? ??
????, ???? ???? ?? ??????? ????? ???? ?????? ??
???? ?????? ???) RemoveWorker 4 ????? ????
??????? (???? ?? ??????? ???) RemoveWorkerImage
5 ????? ????? ?? ???? (??-?? ?"? ?? ????? ??????
??????? ?? ??????) GetWorkerImages 6 ?????
???? ?? ??????? ?? ???? ????? CheckSimilarity 7
????? ???? ?? ??? ????? ???? (????
?????...) DestroySurSys 8 ????? ?-
SurSys ??????? ??' 7 ????? ?????? ????? (Image)
????? threshold ??? 0 ?- 1. ?? ???????
?? ?????? ?? ?????? (?"? ????? ????????
imagesSimilarity) ??? ?????? ???????
?????? ??????. ????? ?????? ????? ????? ??????
??? ????? ??- threshold ???????? ????? ??? ?????
????? ?????. ????, ???????? ????? ??? ????? ????
?????. ?????, ????? ???????? ??? ???? ?? ?"? ????
?? ????? ????? ???? ?????? ????? ?????.
4????? ???? ?'
ifndef SURSYS_H define SURSYS_H include
"image.h" typedef enum FALSE, TRUE
Boolean typedef enum SUCCESS, FAIL,
OUT_OF_MEMORY, BAD_PARAM, .
Result typedef struct SurSys_t SurSys SurSys
CreateSurSys() // or Result CreateSurSys(SurSys
) Result AddWorker(SurSys,int, const char
) Result AddWorkerImage(SurSys,int, Image,
int) Result RemoveWorker(SurSys,int) Result
RemoveWorkerImage(SurSys,int,int) Result
GetWorkerImages(SurSys,int,Image,int ) // id,
Array of Image, size Result CheckSimilarity(SurSys
,Image,double,Boolean ,int , char) void
DestroySurSys(SurSys) endif
5???? ???? ?' ????? ???? 2006
- ???? ?' (20 ??????)
- (8 ??????) ????? ?? ???? ??????? ?? SurSys ???
?????? ????? SurSys.c, ?? ?? - ??????? ?????? ???????. ??? ???? ???? ??
??????? ????? ??. - 2.(9 ??????) ???? ?? ??????? 7 ????? ?' ?? ??
???? ??????? ?????? ????? ?' 1. ?? ?????? - ????? ???? ?????. ?????? ???? ???? ??
????????? ?????? ?????? (???????? ??? ?? ????),
?? - ???? ???? ???????? ???? ?? ADTs ??????? ??? ??
???????? ???? ????? ?? SurSys. - 3.(3 ??????) ????? 3 ???? ????? ??????? ?????
(???????? ?- SurSys) ???????? ?"? ???????? - ????? (??? ????? "???? ?????? ??????", ??? ??
???? ????? ?? ADT(s) ???????).
6????? ???? ?' 1
include SurSys.h include "set.h" struct
SurSys_t Set workSet typedef struct
Worker_t int id char name Set
workerImagesSet Worker typedef struct
WorkerImage_t int id Image im WorkerImage
SurSys
7???? ???? ?' ????? ???? 2006
- ???? ?' (20 ??????)
- (8 ??????) ????? ?? ???? ??????? ?? SurSys ???
?????? ????? SurSys.c, ?? ?? - ??????? ?????? ???????. ??? ???? ???? ??
??????? ????? ??. - 2.(9 ??????) ???? ?? ??????? 7 ????? ?' ?? ??
???? ??????? ?????? ????? ?' 1. - ?? ?????? ????? ???? ?????. ?????? ???? ????
?? ????????? ?????? ?????? (???????? - ??? ?? ????), ??? ???? ???? ???????? ???? ??
ADTs ??????? ??? ?? ???????? ???? - ????? ?? SurSys.
- 3.(3 ??????) ????? 3 ???? ????? ??????? ?????
(???????? ?- SurSys) ???????? ?"? ???????? - ????? (??? ????? "???? ?????? ??????", ??? ??
???? ????? ?? ADT(s) ???????).
8????? ???? ?' 2
Result CheckSimilarity(SurSys s,Image im,double
threshold, Boolean match, int id, char
name) double sim,max_sim 0.0 Worker
curr_w WorkerImage curr_im char tmp_name
NULL if (sNULL ret_valNULL id NULL
name NULL) return BAD_PARAM if (threshold
lt 0 threshold gt1) return INVALID_THRESHOLD SE
T_FOREACH(curr_w,s-gtworkerSet) SET_FOREACH(curr
_im, curr_w-gtworkerImagesSet)
sim imagesSimilarity(curr_im-gtim,im)
if (sim gt max_sim) max_sim
sim id curr_w-gtid
tmp_name curr_w-gtname if
(tmp_name!NULL) name
(char)malloc(strlen(tmp_name)1) if
(name NULL) return OUT_OF_MEMORY
strcpy(name, tmp_name) if
(max_sim gt threshold) match TRUE else
match FALSE return SUCCESS
9???? ???? ?' ????? ???? 2006
- ???? ?' (20 ??????)
- (8 ??????) ????? ?? ???? ??????? ?? SurSys ???
?????? ????? SurSys.c, ?? ?? - ??????? ?????? ???????. ??? ???? ???? ??
??????? ????? ??. - 2.(9 ??????) ???? ?? ??????? 7 ????? ?' ?? ??
???? ??????? ?????? ????? ?' 1. ?? ?????? - ????? ???? ?????. ?????? ???? ???? ??
????????? ?????? ?????? (???????? ??? ?? ????),
?? - ???? ???? ???????? ???? ?? ADTs ??????? ??? ??
???????? ???? ????? ?? SurSys. - 3.(3 ??????) ????? 3 ???? ????? ??????? ?????
(???????? ?- SurSys) ???????? ?"? ???????? - ????? (??? ????? "???? ?????? ??????", ??? ??
???? ????? ?? ADT(s) ???????).
10????? ???? ?' 3
INVALID_THRESHOLD IMAGE_DOENT_EXIST WORKER_ALREA
DY_EXIST
11???? ???? ?' ????? ???? -2006
????? ?????? (Cluster) ??? ????? ?? ??????
???????? ?????? ??????? ??? ????? ??????, ??
???????? ???? ?? ?????? ?????? ????? ???. ??????
?????? ??? ????? ??????? ????????? (Jobs) ?????
?? ?? ?????? ??? (Nodes) ???????? ??????. ?????
????? ????? ???? ????? ?? Node ??????? ?? ??? ??
????? (??????) ???? ??? ??????? ????? ?????? CPU
(??? ??????), ???? ??????? (???? ???) ?????
???? (???? ???). ????? ??????? ?????? ???????
???? ????? (??????), ???? ??????? ??????? ????
????? (?? ???? ??? ????, ??' ??????) ???????
???????? ???? ??????? ??????? ???? (??????, ????
?????? ????? ????). ????? ????? ????? ?? ?????
?? ?? ???? ????? ??-????? 2 ?????? ?? ???? ????.
12???? ???? ?' ????? ???? -2006
???? ?' (20 ??????) ???/? ?? ???? ????? ?? ??????
Cluster. ????? ?-type-?? ???', ?? ????? ?????
????????? ????? ???? CreateCluster ????? ?????
?????? DestroyCluster ????? ?????
?????? AddNode ????? ???? ????? ??????
?????? RemoveNode ????? ???? ????? ??????
?????? MergeClusters - ?????? 2 ??????? ?????
????? ??? ????? ?? ?????? RemoveSubcluster
?????? 2 ??????? ????? ????? ??? ???? ???
?????? ????? IsNodeInCluster ?????? ????? ?????
?????, ????? ??? ????? ???? ?????? IsJobRunnable
?????? ????? ?????? ???????, ???????? ??????
????????? ??? ???? ????? ?? ?????? ?? ?????? ???
?? ?? ?? ?????? ??-????? (???? ?????? ?????
??????) ????? ????? ???? ?????
??. CreateMatchings ?????? ????? ?????? ??????
???????? ???????? ????? ?? ???? "???????" ??
?????? ?? ??? ??????? ???? ?????? ????? ??????.
?????? ?????? ?????...
13????? ???? ?'
ifndef CLUSTER_H define CLUSTER_H typedef enum
FALSE, TRUE Boolean typedef enum SUCCESS,
FAIL, OUT_OF_MEMORY, BAD_PARAM, .
Result typedef struct Cluster_t
Cluster struct Job_t char command int
nodes_num double cpu_size int mem_size int
diskspace_size typedef struct Job_t Job
14????? ???? ?' ????
Cluster CreateCluster() // or Result
CreateCluster(Cluster ) void
DestroyCluster(Cluster c) Result
AddNode(Cluster c,char name,double cpu, int
memsize, int disksize) Result
RemoveNode(Cluster c,char name) Result
MergeCluster(Cluster c1, Cluster c2, Cluster
c3) Result RemoveSubCluster(Cluster c, Cluster
c2, Cluster c3) Result IsNodeInCluster(Cluster
c, char name, Boolean res) Result
IsJobRunnable(Cluster c, Job job, Cluster
res) // res will be null incase the job is
not runnable Result CreateMatching(Cluster c,
Job jobs, int num_jobs, Cluster
matches) endif
15???? ???? ?' ????? ???? -2006
???? ?' (20 ??????) 1. (8 ??????) ????? ?? ????
??????? ?? Cluster ??? ?????? ?- Cluster.c.
???/? ???? ADT(s) ????? ?????? ??????. ????
?????? ???ADT ????? ????? ?? ???????
??????. ???/? ?? ????????. ?? ??????? ??????
?????? ????? ????? ???? ?', ?? ???? ?? ????. 2.
(12 ??????) ?? ???? ?? ??????? 9 ???? ????? ?????
?'. ????? ?????? ?? ????? ?? ?????? ????? ?????
?????? ?????? ?????? ????? ???? ???? ???? ??
?????? ????? ???? ?????? ?????? ??????? "???????"
???? ??????? "???????", ????? ?? ???? ?????? ??
?????? 1 ?-2 ?? ?????? 1 ?-3 ?? ??????? ???????
??? ?????. ???? ??????? ???? ????? ???????, ?????
?? ?????? "??????" ?????? 1, 2, ?-5, ??? ????
????? "??????" ?? ????? 6, ?? ???? ??????? ????
??? ???? ???????. ???? ?????? ????????? ?????
????? ?'
16????? ???? ?' 1
include Set.h include Cluster.h struct
Cluster_t Set nodes typedef struct
Node_t char name double cpu int
mem_size int disk_size Node
17???? ???? ?' ????? ???? -2006
???? ?' (20 ??????) 1. (8 ??????) ????? ?? ????
??????? ?? Cluster ??? ?????? ?- Cluster.c.
???/? ???? ADT(s) ????? ?????? ??????. ????
?????? ???ADT ????? ????? ?? ???????
??????. ???/? ?? ????????. ?? ??????? ??????
?????? ????? ????? ???? ?', ?? ???? ?? ????. 2.
(12 ??????) ?? ???? ?? ??????? 9 ???? ????? ?????
?'. ????? ?????? ?? ????? ?? ?????? ????? ?????
?????? ?????? ?????? ????? ???? ???? ???? ??
?????? ????? ???? ?????? ?????? ??????? "???????"
???? ??????? "???????", ????? ?? ???? ?????? ??
?????? 1 ?-2 ?? ?????? 1 ?-3 ?? ??????? ???????
??? ?????. ???? ??????? ???? ????? ???????, ?????
?? ?????? "??????" ?????? 1, 2, ?-5, ??? ????
????? "??????" ?? ????? 6, ?? ???? ??????? ????
??? ???? ???????. ???? ?????? ????????? ?????
????? ?'
18????? ???? ?' 2
Result CreateMatching(Cluster c, Job jobs, int
num_jobs, Cluster matches) Boolean free_flag
FALSE Cluster sub_cluster NULL, match
NULL if(cNULL jobs NULL num_jobs lt
0) return BAD_PARAM matches (Cluster)
malloc(sizeof(Cluster)num_jobs) if (matches
NULL) return OUT_OF_MEMORY for (int i0
iltnum_jobs i) IsJobRunnable(c, jobsi,
match) (matches)i match if (match
!NULL) RemoveSubCluster(c, match,
sub_cluster) if (free_flag) DistroyCluste
r(c) c sub_cluster free_flag
TRUE return SUCCESS
19SmartFile - ???? 12.3.99
- 1. ???? ?????? ??????? - ADT (35 ??????)
- ????? ????? ? ADT ??? SmartFile ????? ??????
?????? ??????. ? SmartFile - ???? ????? ?????? ????? "???" ?????? ???? ?????
??? ????? ????? (??? ??? ?????? - ?? C ). ???? ?????? ?? ?"???" ?? ?????? ?? ??
??? ????? ????? ,??? ?????? ??????, - ????? ?????? ??????? ?"? ?"???" ??"?.
- ?? ? ADT ????? ??????? ?????
- ????? SmartFile ??? ? SmartFile ?????? ????? ??
???? ???? ???? ??????. - ????? ? SmartFile ????? ??????? ?????? ???? ?
SmartFile (???? ????? ?????). - ????? ???? ???? "?????" ??? ????? ????? ????
???? ????? ?? ?????. - ????? ?? ?????? ??? ????? ???? ??? ???? ?????
????. ???? ????? ??? ???. - ????? ?? ?????? ??? ????? ???? ??? ????? ????
(?????? ????? ?????) ??? ???? ????? ????. - ????? ??? ????? OVERRIDE (??? ????? ???? ?????
??? ???? ????? ????) ?? INSERT (??? ????? ????
???? ??? ???? ????? ????). - ????? ?? ???? ????? ????? ?? ????? ???? ??????.
20SmartFile
- ?????
- ???? ?? ?? ???? ???? ?? ?????? ?? ????? (?????
???? ????? ???? ?????). - ????? ????? ????? ?????? ?"? ????? ????? 0 ????
????? ?????? ???? INSERT. ?????? ?? ???? "????
??? ??????", ????? ?? ????? ????? ????? ????
?????. - ??????SmartFile ?? ????? ???? ???? ????, ???
????? ???? ??"???" ????? ??? ?????? ?????. ????,
????? ???? ??? ??? ??, ????? ????? ????? 0 ????
????? (???? ?????? ?????.) ??? ?????? ????
?????? ???? INSERT.
21- ????? ????? ?? ???? ???? ??????? ?? ???? ????
??? "hello" ??? ?????? ???? ???? ??? ?? ????? ??
????? "Hey\nyou!" - include "SmartFile.h
- int main()
- SF myfile SFResult status char c
- status SFCreate(myfile, hello)
- if (status ! SUCCESS)
- error (can't create SmartFile\n)
- status SFPut (myfile, H)
- SFPut (myfile, e)
- SFPut(myfile, k)
- SFPut (myfile, \n)
- SFDestroy (myfile)
- SFCreate (myfile, "hello")
- status SFJump (myfile, END, 0)
- SFPut (myfile, y) SFPut (myfile, o)
- SFPut (myfile, u) SFPut (myfile, ?)
- SFDelete (myfile)
Hek\n
Hek\nyou?
Hek\nyou!
Hey\nyou!
22SmartFile
- ???? ? ( 12 ??????).
- ?????? ?? ????? ???? ???? ?????, ???? ?? ?????
SmartFile.h ????? - ?? ????? interface)) ?? ? ADT SmartFile.
23???? ?.
- ifndef SMART_H
- define SMART_H
- typedef struct SmartFile_t SF
- typedef enum INSERT, OVERRIDE Mode
- typedef enum START, END Base
- typedef enum SUCCESS, FAILURE, BAD_PARAM,
- SFResult
- SFResult SFCreate (SF file, const char
filename) - SFResult SFPut (SF file, char c)
- void SFDestroy (SF file)
- SFResult SFJump (SF file, Base base, int pos)
- SFResult SFDelete (SF file)
- SFResult SFGet (SF file, char c)
- SFResult SFSetMode (SF file, Mode mode)
- endif
24- ???? ?' (20 ??????)
- ????? ?????? ? ADT ??????? ??? SFUndo ?????
???????? ?? ????? ?? ????? ?????? ????? - ????? (????? ????? ????? ?? ?????? ????, ??? ????
????? ?? ???????? ??? ?????? Undo) ???? ????? - ?????? ??????? ?? ?????? ????? ?? ?? ????? ?????
?????. ?????? - include "SmartFile.h"
- int main()
- SFResult status
- SFCreate (myfile, hello")
- SFJump (myfile, END,0)
- SFPut (myfile, \n) // Hey\nYou!\n
- SFPut (myfile, W) // Hey\nYou!\nW
- SFPut (myfile, o) // Hey\nYou!\nWo
- SFPut (myfile, h) // Hey\nYou!\nWoh
- status SFUndo (myfile) // Hey\nYou!\nWo
- SFUndo (myfile) // Hey\nYou!\nW
- SFPut (myfile,'h') // Hey\nYou!\nWh
- SFPut (myfile, y) // Hey\nYou!\nWhy
- SFPut (myfile, ) // Hey\nYou!\nWhy
25SmartFile
- ??? 1 (2 ??????)
- ?????? ????? ?????? ????? ?' ?? ????? ????????
SFUndo . (??? ???? - ????? ?? ?? ????? ????, ??? ?? ?? ?????
????????). - ??? 2 (10 ??????)
- ???? ????? ???? ?????? ?????? ???? ????? ?? ?????
? Undo. (???? ?????? ??? ???? - ?????? ????? ????? ?? ???????). ??? ???? ?????
?? ???? ???????, ?? ???? ???? ??? ???? - ????? ?????? ????? ??.
- ?????? ???? ???? ??????? ????? ?????? ?????????
SFPut, SFJump, - SFSetMode ? SFDelete ??????? ????? SF ????
????? ?? - ????? ? SFUndo. ???? ?? ??? ???? ????? ??
???????? ?????? ??? ????? Undo. - ??? 3 (8 ??????)
- ???? ?? ???????? SFUndo ????? ???? ???????
?????? ???? ?????. ???? ????? - ?????? ??? ???????? ??????? ????? ?? SF ??? ?????
????? ?'. ???? ?? ??? ???? ????? - ?? ???????? ?????? ??? ????? Undo.
- ???? ? (3 ??????) .
- ??? ????? ?????? ( 3 ) ???? ????? ??? ?????????
?? ????? SF ?????? ?????? (?????
26???? ?.
- ??? 1
- SFResult SFUndo (SF file)
- ??? 2
- ???? ????? ??????? ?????? ??? ???? ????? ????
?????? ? SF. - ??????? ???? ???? ?????? Oper ?????? ?
- typedef enum R,P,D op
- typedef struct Oper_t
- op code
- char old_char
- Oper
- op ??? ??? ?????? ??????
- D - ?? ????. ???? old_char ???? ?? ??? ?????.
- P - ?? ????. old_char ???? ?????.
- R - ?? ?????, ???? old_char ???? ?? ??? ??????.
- ????? ? SetMode ?? ?????.
- ?????? ? Delete ????? ??????? ???? ??? ????? ? op
?? D ??? ??? ?????. - ?????? ? Put ????? ??????? ???? ????? ?? P ? op
?? ??? ???? insert , ?? ?? R ? op ?? ??? ????
override . ???? ?? ?? ???? ?? ??? ????? ?????
???? ? old_char. - ?????? Jump, ? read (????? ????? ???? ??? ???????
? read ? jump) ????? ?? ???????. - ??? ??, ????? ??? ??? ???? ?? ??? ?????? ?????
Undo (??? ?? ??????? ??????? ??? ????? ?' ????
???? ????? ?? ???????? ???????) ?? ???? ??????
?????.
27SmartFile
- ??? 1 (2 ??????)
- ?????? ????? ?????? ????? ?' ?? ????? ????????
SFUndo . (??? ???? - ????? ?? ?? ????? ????, ??? ?? ?? ?????
????????). - ??? 2 (10 ??????)
- ???? ????? ???? ?????? ?????? ???? ????? ?? ?????
? Undo. (???? ?????? ??? ???? - ?????? ????? ????? ?? ???????). ??? ???? ?????
?? ???? ???????, ?? ???? ???? ??? ???? - ????? ?????? ????? ??.
- ?????? ???? ???? ??????? ????? ?????? ?????????
SFPut, SFJump, - SFSetMode ? SFDelete ??????? ????? SF ????
????? ?? - ????? ? SFUndo. ???? ?? ??? ???? ????? ??
???????? ?????? ??? ????? Undo. - ??? 3 (8 ??????)
- ???? ?? ???????? SFUndo ????? ???? ???????
?????? ???? ?????. ???? ????? - ?????? ??? ???????? ??????? ????? ?? SF ??? ?????
????? ?'. ???? ?? ??? ???? ????? - ?? ???????? ?????? ??? ????? Undo.
- ???? ? (3 ??????) .
- ??? ????? ?????? ( 3 ) ???? ????? ??? ?????????
?? ????? SF ?????? ?????? (?????
28???? ?.
- ??? 3
- SFResult SFUndo (SF file)
- SFResult res
- Oper rec
- Mode_t mode file-gtmode
- res pop (file-gts,rec)
- if (res FAIL) return (NoMoreOperation)
- file-gtflag UNDO
- switch (rec.oper)
- case P // Put
- SFDelete(file)
- break
- case R // Replace
- SFSetMode(file, OVERRIDE)
- SFPut(file,rec.old_char)
- SFSetMode(file, mode)
- break
- case D // Delete
- SFSetMode(file, INSERT)
???? ???? ???? ????? ?? ???? ???? ???? ?? ????
????, ?? ?????? ?? ?????? ???????? ???????
???????? ???? ???? ??.
29SmartFile
- ??? 1 (2 ??????)
- ?????? ????? ?????? ????? ?' ?? ????? ????????
SFUndo . (??? ???? - ????? ?? ?? ????? ????, ??? ?? ?? ?????
????????). - ??? 2 (10 ??????)
- ???? ????? ???? ?????? ?????? ???? ????? ?? ?????
? Undo. (???? ?????? ??? ???? - ?????? ????? ????? ?? ???????). ??? ???? ?????
?? ???? ???????, ?? ???? ???? ??? ???? - ????? ?????? ????? ??.
- ?????? ???? ???? ??????? ????? ?????? ?????????
SFPut, SFJump, - SFSetMode ? SFDelete ??????? ????? SF ???? ?????
?? - ????? ? SFUndo. ???? ?? ??? ???? ????? ??
???????? ?????? ??? ????? Undo. - ??? 3 (8 ??????)
- ???? ?? ???????? SFUndo ????? ???? ???????
?????? ???? ?????. ???? ????? - ?????? ??? ???????? ??????? ????? ?? SF ??? ?????
????? ?'. ???? ?? ??? ???? ????? - ?? ???????? ?????? ??? ????? Undo.
- ???? ? (3 ??????) .
- ??? ????? ?????? ( 3 ) ???? ????? ??? ?????????
?? ????? SF ?????? ?????? (?????
30???? ?.
- BadJump ????? ???? ?????? / ??? ?????.
- NoMoreOperation - ??? ???? ?????? ????.
- CannotOpenFile ??? ?????? ????? ?? ?????
- ????? ??????.