星期日, 4月 19, 2009
星期六, 4月 18, 2009
漫談 heap tree
身為一個懶人如我,heap tree 對我而言是一個非常好用的 data structure,其實這篇講的不是很難,只是要講我很懶 XD
我還蠻記得我第一次學習 C++ STL 的時候,我第一次體會到,何謂需求? 如果可以分析資料的基本特性,就可以找到比較弱的方法,而不用每次都用很強的方法。舉個例子說,從一個 ordered list 中取出 max element ,早期的我可能笨笨的排序完就直接上了 (std::sort() 很方便啊 XD),但是如果每次都只是從序列中取出最大或最小元素,可能候用 std::make_heap() 搭配 std::pop_heap() 即可,而且速度比前者快很多,其實大部分我們只是想取某個特性的元素,也不用每次都拿排序來做。如果每次都僅插入元素來形成 ordered list 的話,當然也可以使用 std::list
我記得我在很久以前與人合作寫程式的時候,有人一次讀了數mb進來存在 std::string 中,然後使用 std::string::insert ,這人就問我為什麼跑起來無敵慢,我說原因其實蠻簡單的,因為這個 member function 的時間是 O(n),後來改成分段讀取後處理,速度快了好多啊XD。
題外話: 我沒有用過 Boost::asio 和 Boost::thread ,有人用過的可以告訴我穩定否 XD?
---
寫程式時,盡量使用最弱假設,會有驚喜的。
2009/04/18 5:32 pm 大鳥 在 comments 中有提到更好的方法,不過我還沒試,所以有看的人要記得看回覆喔XD
written by
yen3
in
11:12 上午
4
comments
tag: DA and Algorithm, life, programming
星期五, 4月 17, 2009
星期三, 4月 15, 2009
講
覺得今天講 Java Technicalities 說的不是很好,有點說太快了,也說太淺了,一方面是簡報只有準備這樣子,一方面是時間太短,最大的問題是自己掌握能力太差了...Orz
---
再改進
written by
yen3
in
10:08 下午
0
comments
tag: life
Java I/O
利用現在難得空閒(原本要講 Java Technicalities 因故延期 XD)來寫一下這篇前幾天想寫的東西好了
Java I/O 和 C++ I/O 都是採取 OO 做為設計準則,所以其實 Java I/O 並不難懂,難懂的是,為什麼會有這麼多名詞 ... Orz,其實 Java I/O 大至上可以分為
- InputStream/ OutputStream - 一次讀取以 1 byte 為單位
- Reader/ Writer - 一次讀取以1 char 為單位
由於 Java String 是以 UTF-8 為 default encoding ,所以如果使用 Reader/ Writer ,1 char = ?? bytes ,其實談到 I/O 與 string 躲不掉的就是編碼問題,可是這我也不懂,我們再來大概分類一下XD
- InputStream/ OutputStream
- StringBufferInputStream/ StringBufferOutpuStream - 如前文所提,String 並不一定是 1 char = 1 byte,所以此 class 已經不被建議使用
- ByteArrayInputStream/ ByteArrayOutputStream - 如果你很肯定你的 String 的單位是 1 byte,可以使用這個 class + String.getBytes() 來使用
- FileInputStream/ FileOutputStream - 檔案用的 XD
- Socket.getInputStream()/ Socket.getOutputStream() - 很明顯,這是 Socket Programming 用的XD
- Process.getInputStream()/ Process.getOutputstream() - 這是 Process Control 用的 XD 需用 ProcessBuilder 來建立 Process
- Reader/ Writer
- StringReader/ StringWriter - 官方建議用來讀取 String 的 class
- FileReader/ FileWriter - for file
- CharArrayReader/ CharArrayWriter - 我不想說了XD
其實還有很多沒提到的,但是我們可以把上述的的class再分別接到(做為以下 contructor argument)...
- InputStream/ OutputStream
- BufferedInputStream/ BufferedOutputStream - 加上 buffer
- DataInputStream/ DataOutputStream - 支援格式化輸入輸出
- Reader/ Writer
- BufferedReader/ BufferedWriter - 同樣支援 readLine()/ writeLine()
- 格式化輸入輸出我就不知道了,不過有想到Scanner 可以格式化輸入
看到這邊其實蠻亂的,不過這就是Java...Orz 其實只要記得有兩套方法就可以了,偏偏又跑出一個兩者的單向橋樑...
- InputStreamReader/ OutputStreamWriter - 讓 InputStream/ OutputStream 可以橋接到Reader/ Writer 去,反之不行
其實原因還蠻簡單的,今天我收到的 InputStream/ OutputStream 裡面的字元不一定是以 1 byte 為單位啊(其實知道 encoding 的話,也不難辦),例如說我從 Socket 收到的訊息採用 UTF-8 的話,我們就可以寫出這種程式碼 XD
Socket connect = new Socket("balabala");
BufferedReader br = new BufferedReader(new InputStreamReader(connect.getInputStream()));那麼其他沒有提到的有...
- RandomAccessFile
- ObjectInputStram/ ObjectOutputStream
- java.nio
以後有空再說吧(以後真的會有空嗎... XD)
---
這篇倒是寫蠻快的 XD
written by
yen3
in
1:20 下午
0
comments
tag: learning, life, programming, reading
星期二, 4月 14, 2009
星期一, 4月 13, 2009
錯誤
答答的鍵盤聲是美麗的錯誤 我只是個 programmer 不是 bugger producer ...Orz
---
又要 debug 一陣子了...Orz
written by
yen3
in
9:15 上午
4
comments
星期五, 4月 10, 2009
搬家
第一次住外面, 其實睡不太著。
不過其實習慣了, 或許會覺得這邊很好, 雖然是在二樓, 常聽的到車子的聲音, 但是我意外的蠻習慣車水馬龍聲。搬家也還算順利, 有 fire7617 和 gb014388 幫忙, 真的省事不少(不過最重的書還是得自己搬 XD), 住的地方, 生活機能還算便利, 附近有學校, 如果願意, 可以聽著學校鐘聲醒來, 如果記憶力很好的話, 可以數鐘聲知道現在幾點 XD
近期計畫有三件事, 第一件事, 繼續講 Java Technicalities , 不過大概是針對不同的學弟妹說了, 所以簡報內容得調整才行, 第二件事, 開始寫比賽文件, 是的, 我又繼續比賽了, 不過這次比賽只有寫文件和展示, 兩件事皆非我所長, 還好同組組員很厲害 XDXD, 第三件事, 我想稍微了解 Google Cloud Computing 在做什麼, 希望能讀懂相關 paper, 當然, Real World Haskell 和 Introdution to Functional Programming using Haskell 不在計畫內就代表, 每天都要抽一點時間看就是了。
---
還真是不得閒的日子。
written by
yen3
in
8:07 上午
5
comments
tag: game, life, programming
星期三, 4月 08, 2009
Java Technicalities
其實我跟 Java 不熟,今天卻要對學弟妹做 Java Technicalities 的介紹,好死不死我又用全英文做簡報,硬著頭皮把簡報釋出,我想我的英文應該蠻差的,歡迎盡量指正,然後我會盡量改(泣)
這一次一樣,XeLaTeX code不釋出啦,要的人可以私底下來信。
---
就說了不要獻醜了(拖走~)
written by
yen3
in
10:15 上午
3
comments
tag: latex, learning, life, programming
星期六, 4月 04, 2009
返家
今天搭乘火車站著返家,明天要掃墓,是一個不很愉快的搭車經驗,人擠的跟沙丁魚罐頭沒什麼兩樣XD 也看盡了人生百態。
---
還是不要廢話好了XD
written by
yen3
in
12:23 上午
2
comments
tag: life
星期四, 4月 02, 2009
試試
最近剛好在寫 A* Algorithm , vim 有把純文字轉成 html (:TOhtml)的功能,來試試
1 Add START to OPEN list
2 while OPEN not empty
3 get node n from OPEN that has the lowest f(n)
4 if n is GOAL then return path
5 move n to CLOSED
6 for each n’ = CanMove(n , direction)
7 g(n’) = g(n) + cost(n,n’)
8 calculate f(n’)=g(n’)+h(n’)
9 if n’ in OPEN list and new n’ is not better , continue
10 if n’ in CLOSED list and new n’ is not better , continue
11 remove any n’ from OPEN and CLOSED
12 add n as n’s parent
13 add n’ to OPEN ….. coming up in OPEN
14 end for
15 end while
16 if we get here , then there is No Solution
雖然轉出來的code很醜,如果效果不錯,以後就會用它了... 畢竟我不會寫CSS XD
---
寫完再好好解釋這個 Algorithm :)
written by
yen3
in
9:59 上午
0
comments
星期一, 3月 30, 2009
不順
這,雖然我也是很不順,不過我倒是不以為忤 XD 因為不順,所以我們要吃壽喜燒吃到飽(大誤) XD
最近自己身邊的朋友或多或少遭遇到不順,原因也不盡相同,但是我的方法一向只有多陪陪(所以這或許是我常要吃飯的原因(大誤)),不過我得說,不管是怎麼樣的人,都有不一樣,且自己認為很嚴重的煩惱,我自己沒有煩惱的原因是,都習慣了,哈哈。或許更大的原因是,我很習慣挫敗,因為我的人生很少成功過(誤) XD 可能我自己身處的位置,我看的到,身為一個教授的煩惱,身為一個學生的難為,身為一個情侶的不適,身為一個... 太多了,但是不論無何
我們一定要相信自己,一定會雨過天青,用笑容迎接溫暖的陽光
但是我是雨男,所以可能雨過天青的時候,還有一邊太陽一邊下雨...Orz 不知道有多少,我對於我的生活感到無助時,都是有一堆朋友幫助著我,所以我也會這樣子幫助回去,重點是
不要忘記自己的初衷
我想這就夠了。
---
至於為什麼我是雨男,就別問了 XD
written by
yen3
in
9:52 上午
0
comments
星期六, 3月 28, 2009
損壞
發生的事太多了,我還是用這個標題好了...
MacBook 變壓器 和 Logitech MX1000 相繼損壞,前者在保固期內,不然是2900(沙鍋貴的變壓器啊...Orz),至少要等五個工作天以上...我現在是借 efang 以前的電腦灌 ubuntu 打的,最近學校網路又不穩,我沒有 MacBook 就像武功全廢一樣,但是我下禮拜還要講簡報給學弟妹聽,還有作業要交啊 XD
MX1000 也是死狀其慘,有一天就給你宣告不治,送修說,這個出廠超過三年,不保了喔,但是我只買了兩年多啊啊啊啊(但是我沒有發票...Orz) ,只好再買一隻新的滑鼠了,目前是買了 MX1100 其實我還蠻想知道它是五年保還是三年保,有人知道要怎麼查嗎XD
其他小壞掉的東西就不勝枚舉了...Orz
---
不過最近書倒是看的不少,很開心 :)
written by
yen3
in
10:50 上午
2
comments
tag: life
星期二, 3月 24, 2009
How to set background image in LaTeX
如何在 LaTeX 中設定一份文件的背景圖片? 如果是Word的話,我在以前的 blog 有提過如何解決。如果是 LaTeX 呢?
答案是,wallpaper package,其實還蠻簡單的,估計寫這個package的人蠻有prefix的概念XD。
首先,把這個package包進來\usepackage{wallpaper}其實我們只有兩種指令,一種是另外一種,就是上述全部在前面加上This,代表只對目前這一頁有效XD
\CenterWallPaper
\TileWallPaper % 背景看不到邊喔 XD
\TileSquareWallPaper
\ULCornerWallPaper % upper left
\LLCornerWallPaper % lower left
\URCornerWallPaper
\LRCornerWallPaper
\ClearWallPaper
舉個例子來說好了,如果我們寫\CenterWallPaper{0.25}{background} % 背景圖放在正中間,圖的size 為原圖的 0.25其他的用法,可以參考原廠文件
---
原本以為很難,看來是我錯了XD
written by
yen3
in
8:16 下午
0
comments
tag: latex, programming, software
星期一, 3月 23, 2009
「淺談排版系統 Typesetting System」簡報釋出
廢話不多說,連結在此
簡報 (pdf)
Handout (pdf)
若有問題,歡迎指教指正,至於.tex 的 source code 暫不釋出(因為寫的很難看XD),如果有需要可私下來信索取XD 希望能對排版有基本的認識。
---
禮拜三要講第一次,不知道會怎麼樣XD
written by
yen3
in
11:12 下午
4
comments
tag: learning, linux, programming, reading, software
星期四, 3月 19, 2009
紀念
第一次用 Synopsys Design Version + UMC 90nm Library 合出電路圖,紀念一下。
現在可以理解ycma說的 "layout 才需要大螢幕啊。" 我在筆電上使用就頗痛苦的XD
---
不過看到這樣子的圖產生還是很爽 XD
written by
yen3
in
10:52 上午
0
comments
tag: life
星期二, 3月 17, 2009
Sara Bareilles - Love Song
最近蠻喜歡聽的一首歌
Head under water
And they tell me to breathe easy for a while
The breathing gets harder, even I know that
You made room for me, but it's too soon to see
If I'm happy in your hands
I'm unusually hard to hold on to
Blank stares at blank pages
No easy way to say this
You mean well, but you make this hard on me
I'm not gonna write you a love song
'Cause you asked for it
'Cause you need one, you see
I'm not gonna write you a love song
'Cause you tell me it's make or breaking this
If you're on your way
I'm not gonna write you to stay
If all you have is leaving
I'mma need a better reason to write you a love song today
Today
I learned the hard way
That they all say things you want to hear
My heavy heart sinks deep down under you
And your twisted words, your help just hurts
You are not what I thought you were
Hello to high and dry
Convinced me to please you
Made me think that I need this too
I'm trying to let you hear me as I am
I'm not gonna write you a love song
'Cause you asked for it
'Cause you need one, you see
I'm not gonna write you a love song
'Cause you tell me it's make or breaking this
If you're on your way,
I'm not gonna write you to stay
If all you have is leaving
I'mma need a better reason to write you a love song today
Promise me you'll leave the light on
To help me see with daylight, my guide, gone
'Cause I believe there's a way you can love me because I say
I won't write you a love song
'Cause you asked for it
'Cause you need one, you see
I'm not gonna write you a love song
'Cause you tell me it's make or breaking this
Is that why you wanted a love song
'Cause you asked for it?
'Cause you need one, you see
I'm not gonna write you a love song
'Cause you tell me it's make or breaking this
If you're on your way
I'm not gonna write you to stay
If your heart is nowhere in it
I don't want it for a minute
Babe, I'll walk the seven seas when I believe that there's a reason to
Write you a love song today
Today
---
不過現場的聲音比較沙啞 XD
written by
yen3
in
9:03 上午
0
comments
星期一, 3月 16, 2009
星期三, 3月 11, 2009
2008 Turing Award
今年 Turing Award 發佈之後,ycma 特別來信告知,因為他知道我對 programming language 特別有興趣。今年繼2006年 Frances E. Allen 以第一位女性得到 Turing Award 之後,
2008 的 Turing Award 得主為 Barbara Liskov !!
特將 ycma 轉寄的信節錄於下
ACM has named Barbara Liskov the recipient of the 2008 ACM A.M. Turing Award for her contributions to practical and theoretical foundations of programming language and system design, especially related to data abstraction, fault tolerance, and distributed computing. (yen3 註: 以查 wiki 得到的資料,這邊的特別指定的領域,幾乎都是首先開創。)
Liskov revolutionized the programming field with groundbreaking research that underpins virtually every modern computer application for both consumers and businesses. Her achievements in programming language design have made software more reliable and easier to maintain. They are now the basis of every important programming language since 1975, including Ada, C++, Java, and C#. (yen3 註: 這邊提到的語言我只有 Ada 不會耶,不過這不重要啦 XD)
Liskov heads the Programming Methodology Group in the Computer Science and Artificial Intelligence Laboratory at MIT, where she has conducted research and has been a professor since 1972. (yen3 註: 讀到這邊抽了一口涼氣,讓我想到現在中研院院士,領導自由軟體鑄造場,但是我忘了名字了...Orz)
那麼我又節錄一下,Liskov 女士在 wiki 上的資料
Liskov has led many significant projects, including the design and implementation of CLU, the first programming language to support data abstraction; Argus, the first high-level language to support implementation of distributed programs; and Thor, an object-oriented database system. With Jeannette Wing, she developed a particular definition of subtyping, commonly known as the Liskov substitution principle. She leads the Programming Methodology Group at MIT, with a current research focus in Byzantine Fault Tolerance and distributed computing. (yen3 註: 真的只能對 Liskov 女士以 pioneer 來形容,到現在仍持續研究,真的很很讓人佩服。)
---
感謝老師提供此訊息,不然我可能還不知道 XD
Josh Ko 對我說 Liskov 女士著名的 Liskov Substitution Principle: 這邊有簡介
written by
yen3
in
5:24 下午
0
comments
tag: life, programming
星期一, 3月 09, 2009
Intstall git plug-in in Eclipse
其實我也不會,參考自這篇文章才會的 "Chris Cruft: Eclipse Git plugin installation",詳細說明安裝方法,Eclipse git plug-in 在Linux, Mac OSX底下問題不大,如果是Windows的話就要裝Cygwin,我是在Mac OS下試的,在 Eclipse 3.4.2 下測試,以下是不像翻譯的翻譯 XD
- 從網站中抓回檔案,在command line 底下輸入
git clone git://repo.or.cz/egit.git - 會抓完一個資料夾,在 Eclipse 中,把這個資料夾裡的專案匯入,方法為
File >> Import >> General >> Existing Projects into Workspace >> 選擇該資料夾 >> 確定全部都的project都有被選取到即可下一步(原文寫八個,其實更多) - 把匯入的專案全部build一次
Project >> Build All - 再把compile好的專案匯出,於是選取這些匯入的專案然後
File >> Export >> Plug-in Development >> Deployable plug-ins and fragments目的資料夾選取你的Eclipse 安裝資料夾,匯出後重新開啟 Eclipse - 重新開啟後
對某個專案按右鍵 >> Team >> Share Project應該就可以看到git的相關東西了,之後的設定也是從這個地方(藏的好隱密啊...Orz),或者是從File >> Import >> Git >> Git Repository直接使用現成的git repository也是一個不錯的方法
---
have fun!
written by
yen3
in
7:39 下午
2
comments
tag: learning, programming, software

