Assignment%201%20Debrief - PowerPoint PPT Presentation

About This Presentation
Title:

Assignment%201%20Debrief

Description:

Standard practice in the UNIX world. Describe dependencies among files ... g $(FLAGS) I/usr/include c o bitvector.o bitvector.cpp ... – PowerPoint PPT presentation

Number of Views:25
Avg rating:3.0/5.0
Slides: 21
Provided by: csF2
Learn more at: http://www.cs.fsu.edu
Category:

less

Transcript and Presenter's Notes

Title: Assignment%201%20Debrief


1
Assignment 1 Debrief
  • Andy Wang
  • Data Structures, Algorithms, and Generic
    Programming

2
makefile
  • Reasons for using a makefile
  • Standard practice in the UNIX world
  • Describe dependencies among files
  • Easy to rename files, change include paths, and
    so on
  • Automatically generate header file dependencies

3
A Simple makefile
  • all libbit.a sieve.x
  • libbit.a bitvector.o
  • ar cr libbit.a bitvector.o
  • ranlib libbit.o
  • sieve.x main.o sieve.o libbit.a
  • g -g ansi Wall main.o sieve.o I/usr/include
    L. lbit o sieve.x
  • bitvector.o bitvector.cpp bitvector.h
  • g -g ansi Wall I/usr/include c o
    bitvector.o bitvector.cpp
  • sieve.o sieve.cpp bitvector.h sieve.h
  • g -g ansi Wall I/usr/include c o sieve.o
    sieve.cpp
  • main.o main.cpp sieve.h
  • g -g ansi Wall I/usr/include c o main.o
    main.cpp
  • clean
  • rm f .o libbit.a sieve.x core .bak

4
To ease changing flags
  • FLAGS -g ansi Wall -O
  • all libbit.a sieve.x
  • libbit.a bitvector.o
  • ar cr libbit.a bitvector.o
  • ranlib libbit.o
  • sieve.x main.o sieve.o libbit.a
  • g (FLAGS) main.o sieve.o I/usr/include L.
    lbit o sieve.x
  • bitvector.o bitvector.cpp bitvector.h
  • g (FLAGS) I/usr/include c o bitvector.o
    bitvector.cpp
  • sieve.o sieve.cpp bitvector.h sieve.h
  • g (FLAGS) I/usr/include c o sieve.o
    sieve.cpp
  • main.o main.cpp sieve.h
  • g (FLAGS) I/usr/include c o main.o
    main.cpp
  • clean
  • rm f .o libbit.a sieve.x core .bak

5
make depend
  • FLAGS -g ansi Wall -O
  • all libbit.a sieve.x
  • libbit.a bitvector.o
  • ar cr libbit.a bitvector.o
  • ranlib libbit.o
  • sieve.x main.o sieve.o libbit.a
  • g (FLAGS) main.o sieve.o I/usr/include L.
    lbit o sieve.x
  • bitvector.o bitvector.cpp bitvector.h
  • g (FLAGS) I/usr/include c o bitvector.o
    bitvector.cpp
  • sieve.o sieve.cpp bitvector.h sieve.h
  • g (FLAGS) I/usr/include c o sieve.o
    sieve.cpp
  • main.o main.cpp sieve.h
  • g (FLAGS) I/usr/include c o main.o
    main.cpp
  • clean
  • rm f .o libbit.a sieve.x core .bak
  • depend
  • makedepend -- (FLAGS) I/usr/include
    bitvector.cpp \
  • sieve.cpp main.cpp bitvector.h sieve.h
  • DO NOT DELETE THIS LINE makedepend depends on
    it.

6
Systematic Conversion
  • FLAGS -g ansi Wall -O
  • all libbit.a sieve.x
  • libbit.a bitvector.o
  • ar cr libbit.a bitvector.o
  • ranlib libbit.o
  • sieve.x main.o sieve.o libbit.a
  • g (FLAGS) main.o sieve.o I/usr/include L.
    lbit o sieve.x
  • .cpp.o
  • g (FLAGS) I/usr/include c o .o .cpp
  • clean
  • rm f .o libbit.a sieve.x core .bak
  • depend
  • makedepend -- (FLAGS) I/usr/include
    bitvector.cpp \
  • sieve.cpp main.cpp bitvector.h sieve.h
  • DO NOT DELETE THIS LINE makedepend depends on
    it.

7
To ease changing include paths
  • INC -I/usr/include
  • FLAGS -g ansi Wall -O
  • all libbit.a sieve.x
  • libbit.a bitvector.o
  • ar cr libbit.a bitvector.o
  • ranlib libbit.o
  • sieve.x main.o sieve.o libbit.a
  • g (FLAGS) main.o sieve.o (INC) L. lbit o
    sieve.x
  • .cpp.o
  • g (FLAGS) (INC) c o .o .cpp
  • clean
  • rm f .o libbit.a sieve.x core .bak
  • depend
  • makedepend -- (FLAGS) (INC) bitvector.cpp
    sieve.cpp main.cpp \ bitvector.h sieve.h
  • DO NOT DELETE THIS LINE makedepend depends on
    it.

8
BitVector
70
158
23.16
10010101 00101001 10010010
unsigned char array
array0
array1
array2
ByteNumber(17) 2
Mask(17) 00000010(2)
9
ByteNumber(bit_index)
  • Bad name
  • Should be BasictypeArrayIndexNumber()
  • Goal
  • Return the index of the Basictype array that
    holds the bit

10
Set()
  • Goal
  • 10100010010 ? 1111..11111
  • Arrayj 0x01 // use only 1 out of n bits
  • Arrayj 0xFF // OK only for unsigned char
  • Arrayj 0xFFFFFFFF
  • Arrayj 0x0

11
Set(bit_index)
  • Goal
  • 10100010010 ? 10110010010
  • To set a bit to 1
  • 0 1 ? 1
  • 1 1 ? 1
  • To preserve remaining bits
  • 0 0 ? 0
  • 1 0 ? 1

12
Set(bit_index)
  • 10100010010
  • 00010000000
  • 10110010010
  • ArrayByteNumber(bit_index) Mask(bit_index)

13
Unset()
  • Goal
  • 10100010010 ? 00000.000000
  • 0 0 0
  • 1 0 0
  • Arrayj 0x0
  • 0 0 0
  • 1 1 0
  • Arrayj Arrayj Arrayj

14
A Neat Trick
  • A 11001010
  • B 00100101
  • A A B
  • B A B
  • A A B

15
Unset(bit_index)
  • Goal
  • 10100010010 ? 10000010010
  • To set a bit to 0
  • 0 0 ? 0
  • 1 0 ? 0
  • To preserve remaining bits
  • 0 1 ? 0
  • 1 1 ? 1

16
Unset(bit_index)
  • 10100010010
  • 11011111111
  • 10000010010
  • ArrayByteNumber(bit_index) Mask(bit_index)

17
Flip()
  • Goal
  • 10100010010 ? 01011.101101
  • 1 0
  • 0 1
  • Arrayj Arrayj
  • 1 1 0
  • 0 1 1
  • Arrayj Arrayj 0x0

18
Flip(bit_index)
  • Goal
  • 10100010010 ? 10101010010
  • if (Test(bit_number))
  • Unset(bit_number)
  • else
  • Set(bit_number)

19
Common Errors
  • Basictype vector vs. bit vector
  • ! vs.
  • vs.
  • Mask() vs. BitVectorMask()
  • include ltbitvector.hgt vs. include bitvector.h

20
Common Errors
  • Foo()
  • vs.
  • Foo()

Personally, I prefer Foo()
Write a Comment
User Comments (0)
About PowerShow.com